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/FileSystem.h"
29 #include "llvm/Support/Format.h"
30 #include "llvm/Support/raw_ostream.h"
31 #include "llvm/Support/Host.h"
32 #include "llvm/Support/Process.h"
34 #include "InputInfo.h"
35 #include "ToolChains.h"
37 using namespace clang::driver
;
38 using namespace clang::driver::tools
;
40 /// CheckPreprocessingOptions - Perform some validation of preprocessing
41 /// arguments that is shared with gcc.
42 static void CheckPreprocessingOptions(const Driver
&D
, const ArgList
&Args
) {
43 if (Arg
*A
= Args
.getLastArg(options::OPT_C
, options::OPT_CC
))
44 if (!Args
.hasArg(options::OPT_E
))
45 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
46 << A
->getAsString(Args
) << "-E";
49 /// CheckCodeGenerationOptions - Perform some validation of code generation
50 /// arguments that is shared with gcc.
51 static void CheckCodeGenerationOptions(const Driver
&D
, const ArgList
&Args
) {
52 // In gcc, only ARM checks this, but it seems reasonable to check universally.
53 if (Args
.hasArg(options::OPT_static
))
54 if (const Arg
*A
= Args
.getLastArg(options::OPT_dynamic
,
55 options::OPT_mdynamic_no_pic
))
56 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
57 << A
->getAsString(Args
) << "-static";
60 // Quote target names for inclusion in GNU Make dependency files.
61 // Only the characters '$', '#', ' ', '\t' are quoted.
62 static void QuoteTarget(llvm::StringRef Target
,
63 llvm::SmallVectorImpl
<char> &Res
) {
64 for (unsigned i
= 0, e
= Target
.size(); i
!= e
; ++i
) {
68 // Escape the preceding backslashes
69 for (int j
= i
- 1; j
>= 0 && Target
[j
] == '\\'; --j
)
72 // Escape the space/tab
85 Res
.push_back(Target
[i
]);
89 static void AddLinkerInputs(const ToolChain
&TC
,
90 const InputInfoList
&Inputs
, const ArgList
&Args
,
91 ArgStringList
&CmdArgs
) {
92 const Driver
&D
= TC
.getDriver();
94 for (InputInfoList::const_iterator
95 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
96 const InputInfo
&II
= *it
;
98 if (!TC
.HasNativeLLVMSupport()) {
99 // Don't try to pass LLVM inputs unless we have native support.
100 if (II
.getType() == types::TY_LLVM_IR
||
101 II
.getType() == types::TY_LTO_IR
||
102 II
.getType() == types::TY_LLVM_BC
||
103 II
.getType() == types::TY_LTO_BC
)
104 D
.Diag(clang::diag::err_drv_no_linker_llvm_support
)
105 << TC
.getTripleString();
108 // Add filenames immediately.
109 if (II
.isFilename()) {
110 CmdArgs
.push_back(II
.getFilename());
114 // Otherwise, this is a linker input argument.
115 const Arg
&A
= II
.getInputArg();
117 // Handle reserved library options.
118 if (A
.getOption().matches(options::OPT_Z_reserved_lib_stdcxx
)) {
119 TC
.AddCXXStdlibLibArgs(Args
, CmdArgs
);
120 } else if (A
.getOption().matches(options::OPT_Z_reserved_lib_cckext
)) {
121 TC
.AddCCKextLibArgs(Args
, CmdArgs
);
123 A
.renderAsInput(Args
, CmdArgs
);
127 void Clang::AddPreprocessingOptions(const Driver
&D
,
129 ArgStringList
&CmdArgs
,
130 const InputInfo
&Output
,
131 const InputInfoList
&Inputs
) const {
134 CheckPreprocessingOptions(D
, Args
);
136 Args
.AddLastArg(CmdArgs
, options::OPT_C
);
137 Args
.AddLastArg(CmdArgs
, options::OPT_CC
);
139 // Handle dependency file generation.
140 if ((A
= Args
.getLastArg(options::OPT_M
, 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::SmallString
<128> P(Inputs
[0].getBaseInput());
172 llvm::sys::path::replace_extension(P
, "o");
173 DepTarget
= Args
.MakeArgString(llvm::sys::path::filename(P
));
176 CmdArgs
.push_back("-MT");
177 llvm::SmallString
<128> Quoted
;
178 QuoteTarget(DepTarget
, Quoted
);
179 CmdArgs
.push_back(Args
.MakeArgString(Quoted
));
182 if (A
->getOption().matches(options::OPT_M
) ||
183 A
->getOption().matches(options::OPT_MD
))
184 CmdArgs
.push_back("-sys-header-deps");
187 Args
.AddLastArg(CmdArgs
, options::OPT_MP
);
189 // Convert all -MQ <target> args to -MT <quoted target>
190 for (arg_iterator it
= Args
.filtered_begin(options::OPT_MT
,
192 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
196 if (A
->getOption().matches(options::OPT_MQ
)) {
197 CmdArgs
.push_back("-MT");
198 llvm::SmallString
<128> Quoted
;
199 QuoteTarget(A
->getValue(Args
), Quoted
);
200 CmdArgs
.push_back(Args
.MakeArgString(Quoted
));
202 // -MT flag - no change
204 A
->render(Args
, CmdArgs
);
208 // Add -i* options, and automatically translate to
209 // -include-pch/-include-pth for transparent PCH support. It's
210 // wonky, but we include looking for .gch so we can support seamless
211 // replacement into a build system already set up to be generating
213 bool RenderedImplicitInclude
= false;
214 for (arg_iterator it
= Args
.filtered_begin(options::OPT_clang_i_Group
),
215 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
218 if (A
->getOption().matches(options::OPT_include
)) {
219 bool IsFirstImplicitInclude
= !RenderedImplicitInclude
;
220 RenderedImplicitInclude
= true;
222 // Use PCH if the user requested it.
223 bool UsePCH
= D
.CCCUsePCH
;
225 bool FoundPTH
= false;
226 bool FoundPCH
= false;
227 llvm::sys::Path
P(A
->getValue(Args
));
230 P
.appendSuffix("pch");
231 if (!llvm::sys::fs::exists(P
.str(), Exists
) && Exists
)
238 P
.appendSuffix("pth");
239 if (!llvm::sys::fs::exists(P
.str(), Exists
) && Exists
)
245 if (!FoundPCH
&& !FoundPTH
) {
246 P
.appendSuffix("gch");
247 if (!llvm::sys::fs::exists(P
.str(), Exists
) && Exists
) {
255 if (FoundPCH
|| FoundPTH
) {
256 if (IsFirstImplicitInclude
) {
259 CmdArgs
.push_back("-include-pch");
261 CmdArgs
.push_back("-include-pth");
262 CmdArgs
.push_back(Args
.MakeArgString(P
.str()));
265 // Ignore the PCH if not first on command line and emit warning.
266 D
.Diag(clang::diag::warn_drv_pch_not_first_include
)
267 << P
.str() << A
->getAsString(Args
);
272 // Not translated, render as usual.
274 A
->render(Args
, CmdArgs
);
277 Args
.AddAllArgs(CmdArgs
, options::OPT_D
, options::OPT_U
);
278 Args
.AddAllArgs(CmdArgs
, options::OPT_I_Group
, options::OPT_F
);
280 // Add C++ include arguments, if needed.
281 types::ID InputType
= Inputs
[0].getType();
282 if (types::isCXX(InputType
))
283 getToolChain().AddClangCXXStdlibIncludeArgs(Args
, CmdArgs
);
285 // Add -Wp, and -Xassembler if using the preprocessor.
287 // FIXME: There is a very unfortunate problem here, some troubled
288 // souls abuse -Wp, to pass preprocessor options in gcc syntax. To
289 // really support that we would have to parse and then translate
291 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wp_COMMA
,
292 options::OPT_Xpreprocessor
);
294 // -I- is a deprecated GCC feature, reject it.
295 if (Arg
*A
= Args
.getLastArg(options::OPT_I_
))
296 D
.Diag(clang::diag::err_drv_I_dash_not_supported
) << A
->getAsString(Args
);
298 // If we have a --sysroot, and don't have an explicit -isysroot flag, add an
299 // -isysroot to the CC1 invocation.
300 if (Arg
*A
= Args
.getLastArg(options::OPT__sysroot_EQ
)) {
301 if (!Args
.hasArg(options::OPT_isysroot
)) {
302 CmdArgs
.push_back("-isysroot");
303 CmdArgs
.push_back(A
->getValue(Args
));
308 /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targetting.
310 // FIXME: tblgen this.
311 static const char *getARMTargetCPU(const ArgList
&Args
,
312 const llvm::Triple
&Triple
) {
313 // FIXME: Warn on inconsistent use of -mcpu and -march.
315 // If we have -mcpu=, use that.
316 if (Arg
*A
= Args
.getLastArg(options::OPT_mcpu_EQ
))
317 return A
->getValue(Args
);
319 llvm::StringRef MArch
;
320 if (Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
321 // Otherwise, if we have -march= choose the base CPU for that arch.
322 MArch
= A
->getValue(Args
);
324 // Otherwise, use the Arch from the triple.
325 MArch
= Triple
.getArchName();
328 if (MArch
== "armv2" || MArch
== "armv2a")
330 if (MArch
== "armv3")
332 if (MArch
== "armv3m")
334 if (MArch
== "armv4" || MArch
== "armv4t")
336 if (MArch
== "armv5" || MArch
== "armv5t")
338 if (MArch
== "armv5e" || MArch
== "armv5te")
340 if (MArch
== "armv5tej")
342 if (MArch
== "armv6" || MArch
== "armv6k")
343 return "arm1136jf-s";
344 if (MArch
== "armv6j")
346 if (MArch
== "armv6z" || MArch
== "armv6zk")
347 return "arm1176jzf-s";
348 if (MArch
== "armv6t2")
349 return "arm1156t2-s";
350 if (MArch
== "armv7" || MArch
== "armv7a" || MArch
== "armv7-a")
352 if (MArch
== "armv7r" || MArch
== "armv7-r")
354 if (MArch
== "armv7m" || MArch
== "armv7-m")
356 if (MArch
== "ep9312")
358 if (MArch
== "iwmmxt")
360 if (MArch
== "xscale")
363 // If all else failed, return the most base CPU LLVM supports.
367 /// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular
370 // FIXME: This is redundant with -mcpu, why does LLVM use this.
371 // FIXME: tblgen this, or kill it!
372 static const char *getLLVMArchSuffixForARM(llvm::StringRef CPU
) {
373 if (CPU
== "arm7tdmi" || CPU
== "arm7tdmi-s" || CPU
== "arm710t" ||
374 CPU
== "arm720t" || CPU
== "arm9" || CPU
== "arm9tdmi" ||
375 CPU
== "arm920" || CPU
== "arm920t" || CPU
== "arm922t" ||
376 CPU
== "arm940t" || CPU
== "ep9312")
379 if (CPU
== "arm10tdmi" || CPU
== "arm1020t")
382 if (CPU
== "arm9e" || CPU
== "arm926ej-s" || CPU
== "arm946e-s" ||
383 CPU
== "arm966e-s" || CPU
== "arm968e-s" || CPU
== "arm10e" ||
384 CPU
== "arm1020e" || CPU
== "arm1022e" || CPU
== "xscale" ||
388 if (CPU
== "arm1136j-s" || CPU
== "arm1136jf-s" || CPU
== "arm1176jz-s" ||
389 CPU
== "arm1176jzf-s" || CPU
== "mpcorenovfp" || CPU
== "mpcore")
392 if (CPU
== "arm1156t2-s" || CPU
== "arm1156t2f-s")
395 if (CPU
== "cortex-a8" || CPU
== "cortex-a9")
401 // FIXME: Move to target hook.
402 static bool isSignedCharDefault(const llvm::Triple
&Triple
) {
403 switch (Triple
.getArch()) {
407 case llvm::Triple::ppc
:
408 case llvm::Triple::ppc64
:
409 if (Triple
.getOS() == llvm::Triple::Darwin
)
413 case llvm::Triple::systemz
:
418 void Clang::AddARMTargetArgs(const ArgList
&Args
,
419 ArgStringList
&CmdArgs
) const {
420 const Driver
&D
= getToolChain().getDriver();
421 llvm::Triple Triple
= getToolChain().getTriple();
423 // Select the ABI to use.
425 // FIXME: Support -meabi.
426 const char *ABIName
= 0;
427 if (Arg
*A
= Args
.getLastArg(options::OPT_mabi_EQ
)) {
428 ABIName
= A
->getValue(Args
);
430 // Select the default based on the platform.
431 llvm::StringRef env
= Triple
.getEnvironmentName();
432 if (env
== "gnueabi")
433 ABIName
= "aapcs-linux";
434 else if (env
== "eabi")
437 ABIName
= "apcs-gnu";
439 CmdArgs
.push_back("-target-abi");
440 CmdArgs
.push_back(ABIName
);
442 // Set the CPU based on -march= and -mcpu=.
443 CmdArgs
.push_back("-target-cpu");
444 CmdArgs
.push_back(getARMTargetCPU(Args
, Triple
));
446 // Select the float ABI as determined by -msoft-float, -mhard-float, and
448 llvm::StringRef FloatABI
;
449 if (Arg
*A
= Args
.getLastArg(options::OPT_msoft_float
,
450 options::OPT_mhard_float
,
451 options::OPT_mfloat_abi_EQ
)) {
452 if (A
->getOption().matches(options::OPT_msoft_float
))
454 else if (A
->getOption().matches(options::OPT_mhard_float
))
457 FloatABI
= A
->getValue(Args
);
458 if (FloatABI
!= "soft" && FloatABI
!= "softfp" && FloatABI
!= "hard") {
459 D
.Diag(clang::diag::err_drv_invalid_mfloat_abi
)
460 << A
->getAsString(Args
);
466 // If unspecified, choose the default based on the platform.
467 if (FloatABI
.empty()) {
468 const llvm::Triple
&Triple
= getToolChain().getTriple();
469 switch (Triple
.getOS()) {
470 case llvm::Triple::Darwin
: {
471 // Darwin defaults to "softfp" for v6 and v7.
473 // FIXME: Factor out an ARM class so we can cache the arch somewhere.
474 llvm::StringRef ArchName
=
475 getLLVMArchSuffixForARM(getARMTargetCPU(Args
, Triple
));
476 if (ArchName
.startswith("v6") || ArchName
.startswith("v7"))
483 case llvm::Triple::Linux
: {
484 llvm::StringRef Env
= getToolChain().getTriple().getEnvironmentName();
485 if (Env
== "gnueabi") {
493 // Assume "soft", but warn the user we are guessing.
495 D
.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is
) << "soft";
500 if (FloatABI
== "soft") {
501 // Floating point operations and argument passing are soft.
503 // FIXME: This changes CPP defines, we need -target-soft-float.
504 CmdArgs
.push_back("-msoft-float");
505 CmdArgs
.push_back("-mfloat-abi");
506 CmdArgs
.push_back("soft");
507 } else if (FloatABI
== "softfp") {
508 // Floating point operations are hard, but argument passing is soft.
509 CmdArgs
.push_back("-mfloat-abi");
510 CmdArgs
.push_back("soft");
512 // Floating point operations and argument passing are hard.
513 assert(FloatABI
== "hard" && "Invalid float abi!");
514 CmdArgs
.push_back("-mfloat-abi");
515 CmdArgs
.push_back("hard");
518 // Set appropriate target features for floating point mode.
520 // FIXME: Note, this is a hack, the LLVM backend doesn't actually use these
521 // yet (it uses the -mfloat-abi and -msoft-float options above), and it is
522 // stripped out by the ARM target.
524 // Use software floating point operations?
525 if (FloatABI
== "soft") {
526 CmdArgs
.push_back("-target-feature");
527 CmdArgs
.push_back("+soft-float");
530 // Use software floating point argument passing?
531 if (FloatABI
!= "hard") {
532 CmdArgs
.push_back("-target-feature");
533 CmdArgs
.push_back("+soft-float-abi");
538 // FIXME: Centralize feature selection, defaulting shouldn't be also in the
540 if (const Arg
*A
= Args
.getLastArg(options::OPT_mfpu_EQ
)) {
541 llvm::StringRef FPU
= A
->getValue(Args
);
543 // Set the target features based on the FPU.
544 if (FPU
== "fpa" || FPU
== "fpe2" || FPU
== "fpe3" || FPU
== "maverick") {
545 // Disable any default FPU support.
546 CmdArgs
.push_back("-target-feature");
547 CmdArgs
.push_back("-vfp2");
548 CmdArgs
.push_back("-target-feature");
549 CmdArgs
.push_back("-vfp3");
550 CmdArgs
.push_back("-target-feature");
551 CmdArgs
.push_back("-neon");
552 } else if (FPU
== "vfp") {
553 CmdArgs
.push_back("-target-feature");
554 CmdArgs
.push_back("+vfp2");
555 } else if (FPU
== "vfp3") {
556 CmdArgs
.push_back("-target-feature");
557 CmdArgs
.push_back("+vfp3");
558 } else if (FPU
== "neon") {
559 CmdArgs
.push_back("-target-feature");
560 CmdArgs
.push_back("+neon");
562 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
566 void Clang::AddMIPSTargetArgs(const ArgList
&Args
,
567 ArgStringList
&CmdArgs
) const {
568 const Driver
&D
= getToolChain().getDriver();
570 // Select the ABI to use.
571 const char *ABIName
= 0;
572 if (Arg
*A
= Args
.getLastArg(options::OPT_mabi_EQ
)) {
573 ABIName
= A
->getValue(Args
);
578 CmdArgs
.push_back("-target-abi");
579 CmdArgs
.push_back(ABIName
);
581 if (const Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
582 llvm::StringRef MArch
= A
->getValue(Args
);
583 CmdArgs
.push_back("-target-cpu");
585 if ((MArch
== "r2000") || (MArch
== "r3000"))
586 CmdArgs
.push_back("mips1");
587 else if (MArch
== "r6000")
588 CmdArgs
.push_back("mips2");
590 CmdArgs
.push_back(MArch
.str().c_str());
593 // Select the float ABI as determined by -msoft-float, -mhard-float, and
594 llvm::StringRef FloatABI
;
595 if (Arg
*A
= Args
.getLastArg(options::OPT_msoft_float
,
596 options::OPT_mhard_float
)) {
597 if (A
->getOption().matches(options::OPT_msoft_float
))
599 else if (A
->getOption().matches(options::OPT_mhard_float
))
603 // If unspecified, choose the default based on the platform.
604 if (FloatABI
.empty()) {
605 // Assume "soft", but warn the user we are guessing.
607 D
.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is
) << "soft";
610 if (FloatABI
== "soft") {
611 // Floating point operations and argument passing are soft.
613 // FIXME: This changes CPP defines, we need -target-soft-float.
614 CmdArgs
.push_back("-msoft-float");
616 assert(FloatABI
== "hard" && "Invalid float abi!");
617 CmdArgs
.push_back("-mhard-float");
621 void Clang::AddSparcTargetArgs(const ArgList
&Args
,
622 ArgStringList
&CmdArgs
) const {
623 const Driver
&D
= getToolChain().getDriver();
625 if (const Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
626 llvm::StringRef MArch
= A
->getValue(Args
);
627 CmdArgs
.push_back("-target-cpu");
628 CmdArgs
.push_back(MArch
.str().c_str());
631 // Select the float ABI as determined by -msoft-float, -mhard-float, and
632 llvm::StringRef FloatABI
;
633 if (Arg
*A
= Args
.getLastArg(options::OPT_msoft_float
,
634 options::OPT_mhard_float
)) {
635 if (A
->getOption().matches(options::OPT_msoft_float
))
637 else if (A
->getOption().matches(options::OPT_mhard_float
))
641 // If unspecified, choose the default based on the platform.
642 if (FloatABI
.empty()) {
643 switch (getToolChain().getTriple().getOS()) {
645 // Assume "soft", but warn the user we are guessing.
647 D
.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is
) << "soft";
652 if (FloatABI
== "soft") {
653 // Floating point operations and argument passing are soft.
655 // FIXME: This changes CPP defines, we need -target-soft-float.
656 CmdArgs
.push_back("-msoft-float");
657 CmdArgs
.push_back("soft");
658 CmdArgs
.push_back("-target-feature");
659 CmdArgs
.push_back("+soft-float");
661 assert(FloatABI
== "hard" && "Invalid float abi!");
662 CmdArgs
.push_back("-mhard-float");
666 void Clang::AddX86TargetArgs(const ArgList
&Args
,
667 ArgStringList
&CmdArgs
) const {
668 if (!Args
.hasFlag(options::OPT_mred_zone
,
669 options::OPT_mno_red_zone
,
671 Args
.hasArg(options::OPT_mkernel
) ||
672 Args
.hasArg(options::OPT_fapple_kext
))
673 CmdArgs
.push_back("-disable-red-zone");
675 if (Args
.hasFlag(options::OPT_msoft_float
,
676 options::OPT_mno_soft_float
,
678 CmdArgs
.push_back("-no-implicit-float");
680 const char *CPUName
= 0;
681 if (const Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
682 if (llvm::StringRef(A
->getValue(Args
)) == "native") {
683 // FIXME: Reject attempts to use -march=native unless the target matches
686 // FIXME: We should also incorporate the detected target features for use
688 std::string CPU
= llvm::sys::getHostCPUName();
690 CPUName
= Args
.MakeArgString(CPU
);
692 CPUName
= A
->getValue(Args
);
695 // Select the default CPU if none was given (or detection failed).
697 // FIXME: Need target hooks.
698 if (getToolChain().getOS().startswith("darwin")) {
699 if (getToolChain().getArchName() == "x86_64")
701 else if (getToolChain().getArchName() == "i386")
703 } else if (getToolChain().getOS().startswith("haiku")) {
704 if (getToolChain().getArchName() == "x86_64")
706 else if (getToolChain().getArchName() == "i386")
708 } else if (getToolChain().getOS().startswith("openbsd")) {
709 if (getToolChain().getArchName() == "x86_64")
711 else if (getToolChain().getArchName() == "i386")
714 if (getToolChain().getArchName() == "x86_64")
716 else if (getToolChain().getArchName() == "i386")
717 CPUName
= "pentium4";
722 CmdArgs
.push_back("-target-cpu");
723 CmdArgs
.push_back(CPUName
);
726 for (arg_iterator it
= Args
.filtered_begin(options::OPT_m_x86_Features_Group
),
727 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
728 llvm::StringRef Name
= (*it
)->getOption().getName();
732 assert(Name
.startswith("-m") && "Invalid feature name.");
733 Name
= Name
.substr(2);
735 bool IsNegative
= Name
.startswith("no-");
737 Name
= Name
.substr(3);
739 CmdArgs
.push_back("-target-feature");
740 CmdArgs
.push_back(Args
.MakeArgString((IsNegative
? "-" : "+") + Name
));
744 static bool needsExceptions(const ArgList
&Args
, types::ID InputType
,
745 const llvm::Triple
&Triple
) {
746 // Handle -fno-exceptions.
747 if (Arg
*A
= Args
.getLastArg(options::OPT_fexceptions
,
748 options::OPT_fno_exceptions
)) {
749 if (A
->getOption().matches(options::OPT_fexceptions
))
755 // Otherwise, C++ inputs use exceptions.
756 if (types::isCXX(InputType
))
759 // As do Objective-C non-fragile ABI inputs and all Objective-C inputs on
760 // x86_64 and ARM after SnowLeopard.
761 if (types::isObjC(InputType
)) {
762 if (Args
.hasArg(options::OPT_fobjc_nonfragile_abi
))
764 if (Triple
.getOS() != llvm::Triple::Darwin
)
766 return (Triple
.getDarwinMajorNumber() >= 9 &&
767 (Triple
.getArch() == llvm::Triple::x86_64
||
768 Triple
.getArch() == llvm::Triple::arm
));
774 void Clang::ConstructJob(Compilation
&C
, const JobAction
&JA
,
775 const InputInfo
&Output
,
776 const InputInfoList
&Inputs
,
778 const char *LinkingOutput
) const {
779 bool KernelOrKext
= Args
.hasArg(options::OPT_mkernel
,
780 options::OPT_fapple_kext
);
781 const Driver
&D
= getToolChain().getDriver();
782 ArgStringList CmdArgs
;
784 assert(Inputs
.size() == 1 && "Unable to handle multiple inputs.");
786 // Invoke ourselves in -cc1 mode.
788 // FIXME: Implement custom jobs for internal actions.
789 CmdArgs
.push_back("-cc1");
791 // Add the "effective" target triple.
792 CmdArgs
.push_back("-triple");
793 std::string TripleStr
= getToolChain().ComputeEffectiveClangTriple(Args
);
794 CmdArgs
.push_back(Args
.MakeArgString(TripleStr
));
796 // Select the appropriate action.
797 bool IsRewriter
= false;
798 if (isa
<AnalyzeJobAction
>(JA
)) {
799 assert(JA
.getType() == types::TY_Plist
&& "Invalid output type.");
800 CmdArgs
.push_back("-analyze");
801 } else if (isa
<PreprocessJobAction
>(JA
)) {
802 if (Output
.getType() == types::TY_Dependencies
)
803 CmdArgs
.push_back("-Eonly");
805 CmdArgs
.push_back("-E");
806 } else if (isa
<AssembleJobAction
>(JA
)) {
807 CmdArgs
.push_back("-emit-obj");
809 // At -O0, we use -mrelax-all by default.
811 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
))
812 IsOpt
= !A
->getOption().matches(options::OPT_O0
);
813 if (Args
.hasFlag(options::OPT_mrelax_all
,
814 options::OPT_mno_relax_all
,
816 CmdArgs
.push_back("-mrelax-all");
818 // When using an integrated assembler, translate -Wa, and -Xassembler
820 for (arg_iterator it
= Args
.filtered_begin(options::OPT_Wa_COMMA
,
821 options::OPT_Xassembler
),
822 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
826 for (unsigned i
= 0, e
= A
->getNumValues(); i
!= e
; ++i
) {
827 llvm::StringRef Value
= A
->getValue(Args
, i
);
829 if (Value
== "-force_cpusubtype_ALL") {
830 // Do nothing, this is the default and we don't support anything else.
831 } else if (Value
== "-L") {
832 // We don't support -L yet, but it isn't important enough to error
833 // on. No one should really be using it for a semantic change.
834 D
.Diag(clang::diag::warn_drv_unsupported_option_argument
)
835 << A
->getOption().getName() << Value
;
837 D
.Diag(clang::diag::err_drv_unsupported_option_argument
)
838 << A
->getOption().getName() << Value
;
843 // Also ignore explicit -force_cpusubtype_ALL option.
844 (void) Args
.hasArg(options::OPT_force__cpusubtype__ALL
);
845 } else if (isa
<PrecompileJobAction
>(JA
)) {
846 // Use PCH if the user requested it.
847 bool UsePCH
= D
.CCCUsePCH
;
850 CmdArgs
.push_back("-emit-pch");
852 CmdArgs
.push_back("-emit-pth");
854 assert(isa
<CompileJobAction
>(JA
) && "Invalid action for clang tool.");
856 if (JA
.getType() == types::TY_Nothing
) {
857 CmdArgs
.push_back("-fsyntax-only");
858 } else if (JA
.getType() == types::TY_LLVM_IR
||
859 JA
.getType() == types::TY_LTO_IR
) {
860 CmdArgs
.push_back("-emit-llvm");
861 } else if (JA
.getType() == types::TY_LLVM_BC
||
862 JA
.getType() == types::TY_LTO_BC
) {
863 CmdArgs
.push_back("-emit-llvm-bc");
864 } else if (JA
.getType() == types::TY_PP_Asm
) {
865 CmdArgs
.push_back("-S");
866 } else if (JA
.getType() == types::TY_AST
) {
867 CmdArgs
.push_back("-emit-pch");
868 } else if (JA
.getType() == types::TY_RewrittenObjC
) {
869 CmdArgs
.push_back("-rewrite-objc");
872 assert(JA
.getType() == types::TY_PP_Asm
&&
873 "Unexpected output type!");
877 // The make clang go fast button.
878 CmdArgs
.push_back("-disable-free");
880 // Disable the verification pass in -asserts builds.
882 CmdArgs
.push_back("-disable-llvm-verifier");
885 // Set the main file name, so that debug info works even with
887 CmdArgs
.push_back("-main-file-name");
888 CmdArgs
.push_back(darwin::CC1::getBaseInputName(Args
, Inputs
));
890 // Some flags which affect the language (via preprocessor
891 // defines). See darwin::CC1::AddCPPArgs.
892 if (Args
.hasArg(options::OPT_static
))
893 CmdArgs
.push_back("-static-define");
895 if (isa
<AnalyzeJobAction
>(JA
)) {
896 // Enable region store model by default.
897 CmdArgs
.push_back("-analyzer-store=region");
899 // Treat blocks as analysis entry points.
900 CmdArgs
.push_back("-analyzer-opt-analyze-nested-blocks");
902 // Add default argument set.
903 if (!Args
.hasArg(options::OPT__analyzer_no_default_checks
)) {
904 types::ID InputType
= Inputs
[0].getType();
906 // Checks to perform for all language types.
907 CmdArgs
.push_back("-analyzer-check-dead-stores");
909 // Checks to perform for Objective-C/Objective-C++.
910 if (types::isObjC(InputType
)) {
911 CmdArgs
.push_back("-analyzer-check-objc-methodsigs");
912 CmdArgs
.push_back("-analyzer-check-objc-unused-ivars");
913 // Do not enable the missing -dealloc check.
914 // '-analyzer-check-objc-missing-dealloc',
917 // Checks to perform for all languages *except* C++.
918 if (!types::isCXX(InputType
)) {
919 // Do not enable the security-syntatic check since it
920 // it needs to be refined (known issues).
921 // CmdArgs.push_back("-analyzer-check-security-syntactic");
923 // NOTE: Leaving -analyzer-check-objc-mem here is intentional.
924 // It also checks C code.
925 CmdArgs
.push_back("-analyzer-check-objc-mem");
927 CmdArgs
.push_back("-analyzer-eagerly-assume");
928 CmdArgs
.push_back("-analyzer-check-idempotent-operations");
932 // Set the output format. The default is plist, for (lame) historical
934 CmdArgs
.push_back("-analyzer-output");
935 if (Arg
*A
= Args
.getLastArg(options::OPT__analyzer_output
))
936 CmdArgs
.push_back(A
->getValue(Args
));
938 CmdArgs
.push_back("plist");
940 // Disable the presentation of standard compiler warnings when
941 // using --analyze. We only want to show static analyzer diagnostics
942 // or frontend errors.
943 CmdArgs
.push_back("-w");
945 // Add -Xanalyzer arguments when running as analyzer.
946 Args
.AddAllArgValues(CmdArgs
, options::OPT_Xanalyzer
);
949 CheckCodeGenerationOptions(D
, Args
);
951 // Perform argument translation for LLVM backend. This
952 // takes some care in reconciling with llvm-gcc. The
953 // issue is that llvm-gcc translates these options based on
954 // the values in cc1, whereas we are processing based on
955 // the driver arguments.
957 // This comes from the default translation the driver + cc1
958 // would do to enable flag_pic.
960 // FIXME: Centralize this code.
961 bool PICEnabled
= (Args
.hasArg(options::OPT_fPIC
) ||
962 Args
.hasArg(options::OPT_fpic
) ||
963 Args
.hasArg(options::OPT_fPIE
) ||
964 Args
.hasArg(options::OPT_fpie
));
965 bool PICDisabled
= (Args
.hasArg(options::OPT_mkernel
) ||
966 Args
.hasArg(options::OPT_static
));
967 const char *Model
= getToolChain().GetForcedPicModel();
969 if (Args
.hasArg(options::OPT_mdynamic_no_pic
))
970 Model
= "dynamic-no-pic";
971 else if (PICDisabled
)
976 Model
= getToolChain().GetDefaultRelocationModel();
978 if (llvm::StringRef(Model
) != "pic") {
979 CmdArgs
.push_back("-mrelocation-model");
980 CmdArgs
.push_back(Model
);
983 // Infer the __PIC__ value.
985 // FIXME: This isn't quite right on Darwin, which always sets
987 if (strcmp(Model
, "pic") == 0 || strcmp(Model
, "dynamic-no-pic") == 0) {
988 CmdArgs
.push_back("-pic-level");
989 CmdArgs
.push_back(Args
.hasArg(options::OPT_fPIC
) ? "2" : "1");
991 if (!Args
.hasFlag(options::OPT_fmerge_all_constants
,
992 options::OPT_fno_merge_all_constants
))
993 CmdArgs
.push_back("-no-merge-all-constants");
995 // LLVM Code Generator Options.
997 // FIXME: Set --enable-unsafe-fp-math.
998 if (Args
.hasFlag(options::OPT_fno_omit_frame_pointer
,
999 options::OPT_fomit_frame_pointer
))
1000 CmdArgs
.push_back("-mdisable-fp-elim");
1001 if (!Args
.hasFlag(options::OPT_fzero_initialized_in_bss
,
1002 options::OPT_fno_zero_initialized_in_bss
))
1003 CmdArgs
.push_back("-mno-zero-initialized-in-bss");
1004 if (Args
.hasFlag(options::OPT_fno_strict_aliasing
,
1005 options::OPT_fstrict_aliasing
,
1007 CmdArgs
.push_back("-relaxed-aliasing");
1009 // Decide whether to use verbose asm. Verbose assembly is the default on
1010 // toolchains which have the integrated assembler on by default.
1011 bool IsVerboseAsmDefault
= getToolChain().IsIntegratedAssemblerDefault();
1012 if (Args
.hasFlag(options::OPT_fverbose_asm
, options::OPT_fno_verbose_asm
,
1013 IsVerboseAsmDefault
) ||
1014 Args
.hasArg(options::OPT_dA
))
1015 CmdArgs
.push_back("-masm-verbose");
1017 if (Args
.hasArg(options::OPT_fdebug_pass_structure
)) {
1018 CmdArgs
.push_back("-mdebug-pass");
1019 CmdArgs
.push_back("Structure");
1021 if (Args
.hasArg(options::OPT_fdebug_pass_arguments
)) {
1022 CmdArgs
.push_back("-mdebug-pass");
1023 CmdArgs
.push_back("Arguments");
1026 // Enable -mconstructor-aliases except on darwin, where we have to
1027 // work around a linker bug; see <rdar://problem/7651567>.
1028 if (getToolChain().getTriple().getOS() != llvm::Triple::Darwin
)
1029 CmdArgs
.push_back("-mconstructor-aliases");
1031 // This is a coarse approximation of what llvm-gcc actually does, both
1032 // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
1033 // complicated ways.
1034 bool AsynchronousUnwindTables
=
1035 Args
.hasFlag(options::OPT_fasynchronous_unwind_tables
,
1036 options::OPT_fno_asynchronous_unwind_tables
,
1037 getToolChain().IsUnwindTablesDefault() &&
1039 if (Args
.hasFlag(options::OPT_funwind_tables
, options::OPT_fno_unwind_tables
,
1040 AsynchronousUnwindTables
))
1041 CmdArgs
.push_back("-munwind-tables");
1043 if (Arg
*A
= Args
.getLastArg(options::OPT_flimited_precision_EQ
)) {
1044 CmdArgs
.push_back("-mlimit-float-precision");
1045 CmdArgs
.push_back(A
->getValue(Args
));
1048 // FIXME: Handle -mtune=.
1049 (void) Args
.hasArg(options::OPT_mtune_EQ
);
1051 if (Arg
*A
= Args
.getLastArg(options::OPT_mcmodel_EQ
)) {
1052 CmdArgs
.push_back("-mcode-model");
1053 CmdArgs
.push_back(A
->getValue(Args
));
1056 // Add target specific cpu and features flags.
1057 switch(getToolChain().getTriple().getArch()) {
1061 case llvm::Triple::arm
:
1062 case llvm::Triple::thumb
:
1063 AddARMTargetArgs(Args
, CmdArgs
);
1066 case llvm::Triple::mips
:
1067 case llvm::Triple::mipsel
:
1068 AddMIPSTargetArgs(Args
, CmdArgs
);
1071 case llvm::Triple::sparc
:
1072 AddSparcTargetArgs(Args
, CmdArgs
);
1075 case llvm::Triple::x86
:
1076 case llvm::Triple::x86_64
:
1077 AddX86TargetArgs(Args
, CmdArgs
);
1081 // Pass the linker version in use.
1082 if (Arg
*A
= Args
.getLastArg(options::OPT_mlinker_version_EQ
)) {
1083 CmdArgs
.push_back("-target-linker-version");
1084 CmdArgs
.push_back(A
->getValue(Args
));
1087 // -mno-omit-leaf-frame-pointer is default.
1088 if (Args
.hasFlag(options::OPT_momit_leaf_frame_pointer
,
1089 options::OPT_mno_omit_leaf_frame_pointer
, false))
1090 CmdArgs
.push_back("-momit-leaf-frame-pointer");
1092 // -fno-math-errno is default.
1093 if (Args
.hasFlag(options::OPT_fmath_errno
,
1094 options::OPT_fno_math_errno
,
1096 CmdArgs
.push_back("-fmath-errno");
1098 // Explicitly error on some things we know we don't support and can't just
1100 types::ID InputType
= Inputs
[0].getType();
1101 if (!Args
.hasArg(options::OPT_fallow_unsupported
)) {
1103 if ((Unsupported
= Args
.getLastArg(options::OPT_MG
)) ||
1104 (Unsupported
= Args
.getLastArg(options::OPT_iframework
)))
1105 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1106 << Unsupported
->getOption().getName();
1108 if (types::isCXX(InputType
) &&
1109 getToolChain().getTriple().getOS() == llvm::Triple::Darwin
&&
1110 getToolChain().getTriple().getArch() == llvm::Triple::x86
) {
1111 if ((Unsupported
= Args
.getLastArg(options::OPT_fapple_kext
)))
1112 D
.Diag(clang::diag::err_drv_clang_unsupported_opt_cxx_darwin_i386
)
1113 << Unsupported
->getOption().getName();
1117 Args
.AddAllArgs(CmdArgs
, options::OPT_v
);
1118 Args
.AddLastArg(CmdArgs
, options::OPT_H
);
1119 Args
.AddLastArg(CmdArgs
, options::OPT_P
);
1120 Args
.AddLastArg(CmdArgs
, options::OPT_print_ivar_layout
);
1122 // Special case debug options to only pass -g to clang. This is
1124 Args
.ClaimAllArgs(options::OPT_g_Group
);
1125 if (Arg
*A
= Args
.getLastArg(options::OPT_g_Group
))
1126 if (!A
->getOption().matches(options::OPT_g0
))
1127 CmdArgs
.push_back("-g");
1129 Args
.AddAllArgs(CmdArgs
, options::OPT_ffunction_sections
);
1130 Args
.AddAllArgs(CmdArgs
, options::OPT_fdata_sections
);
1132 Args
.AddAllArgs(CmdArgs
, options::OPT_finstrument_functions
);
1134 Args
.AddLastArg(CmdArgs
, options::OPT_nostdinc
);
1135 Args
.AddLastArg(CmdArgs
, options::OPT_nostdincxx
);
1136 Args
.AddLastArg(CmdArgs
, options::OPT_nobuiltininc
);
1138 // Pass the path to compiler resource files.
1139 CmdArgs
.push_back("-resource-dir");
1140 CmdArgs
.push_back(D
.ResourceDir
.c_str());
1142 Args
.AddLastArg(CmdArgs
, options::OPT_working_directory
);
1144 // Add preprocessing options like -I, -D, etc. if we are using the
1147 // FIXME: Support -fpreprocessed
1148 if (types::getPreprocessedType(InputType
) != types::TY_INVALID
)
1149 AddPreprocessingOptions(D
, Args
, CmdArgs
, Output
, Inputs
);
1151 // Manually translate -O to -O2 and -O4 to -O3; let clang reject
1153 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
)) {
1154 if (A
->getOption().matches(options::OPT_O4
))
1155 CmdArgs
.push_back("-O3");
1156 else if (A
->getOption().matches(options::OPT_O
) &&
1157 A
->getValue(Args
)[0] == '\0')
1158 CmdArgs
.push_back("-O2");
1159 else if (A
->getOption().matches(options::OPT_O
) &&
1160 A
->getValue(Args
)[0] == 'z' &&
1161 A
->getValue(Args
)[1] == '\0')
1162 CmdArgs
.push_back("-Os");
1164 A
->render(Args
, CmdArgs
);
1167 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
);
1168 Args
.AddLastArg(CmdArgs
, options::OPT_pedantic
);
1169 Args
.AddLastArg(CmdArgs
, options::OPT_pedantic_errors
);
1170 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
1172 // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi}
1173 // (-ansi is equivalent to -std=c89).
1175 // If a std is supplied, only add -trigraphs if it follows the
1177 if (Arg
*Std
= Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
1178 if (Std
->getOption().matches(options::OPT_ansi
))
1179 if (types::isCXX(InputType
))
1180 CmdArgs
.push_back("-std=c++98");
1182 CmdArgs
.push_back("-std=c89");
1184 Std
->render(Args
, CmdArgs
);
1186 if (Arg
*A
= Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
,
1187 options::OPT_trigraphs
))
1189 A
->render(Args
, CmdArgs
);
1191 // Honor -std-default.
1193 // FIXME: Clang doesn't correctly handle -std= when the input language
1194 // doesn't match. For the time being just ignore this for C++ inputs;
1195 // eventually we want to do all the standard defaulting here instead of
1196 // splitting it between the driver and clang -cc1.
1197 if (!types::isCXX(InputType
))
1198 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
1199 "-std=", /*Joined=*/true);
1200 Args
.AddLastArg(CmdArgs
, options::OPT_trigraphs
);
1203 // Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'.
1204 if (Arg
*Asm
= Args
.getLastArg(options::OPT_fasm
, options::OPT_fno_asm
)) {
1205 if (Asm
->getOption().matches(options::OPT_fasm
))
1206 CmdArgs
.push_back("-fgnu-keywords");
1208 CmdArgs
.push_back("-fno-gnu-keywords");
1211 if (Arg
*A
= Args
.getLastArg(options::OPT_ftemplate_depth_
)) {
1212 CmdArgs
.push_back("-ftemplate-depth");
1213 CmdArgs
.push_back(A
->getValue(Args
));
1216 if (Arg
*A
= Args
.getLastArg(options::OPT_Wlarge_by_value_copy_EQ
,
1217 options::OPT_Wlarge_by_value_copy_def
)) {
1218 CmdArgs
.push_back("-Wlarge-by-value-copy");
1219 if (A
->getNumValues())
1220 CmdArgs
.push_back(A
->getValue(Args
));
1222 CmdArgs
.push_back("64"); // default value for -Wlarge-by-value-copy.
1225 if (Args
.hasArg(options::OPT__relocatable_pch
))
1226 CmdArgs
.push_back("-relocatable-pch");
1228 if (Arg
*A
= Args
.getLastArg(options::OPT_fconstant_string_class_EQ
)) {
1229 CmdArgs
.push_back("-fconstant-string-class");
1230 CmdArgs
.push_back(A
->getValue(Args
));
1233 if (Arg
*A
= Args
.getLastArg(options::OPT_ftabstop_EQ
)) {
1234 CmdArgs
.push_back("-ftabstop");
1235 CmdArgs
.push_back(A
->getValue(Args
));
1238 CmdArgs
.push_back("-ferror-limit");
1239 if (Arg
*A
= Args
.getLastArg(options::OPT_ferror_limit_EQ
))
1240 CmdArgs
.push_back(A
->getValue(Args
));
1242 CmdArgs
.push_back("19");
1244 if (Arg
*A
= Args
.getLastArg(options::OPT_fmacro_backtrace_limit_EQ
)) {
1245 CmdArgs
.push_back("-fmacro-backtrace-limit");
1246 CmdArgs
.push_back(A
->getValue(Args
));
1249 if (Arg
*A
= Args
.getLastArg(options::OPT_ftemplate_backtrace_limit_EQ
)) {
1250 CmdArgs
.push_back("-ftemplate-backtrace-limit");
1251 CmdArgs
.push_back(A
->getValue(Args
));
1254 // Pass -fmessage-length=.
1255 CmdArgs
.push_back("-fmessage-length");
1256 if (Arg
*A
= Args
.getLastArg(options::OPT_fmessage_length_EQ
)) {
1257 CmdArgs
.push_back(A
->getValue(Args
));
1259 // If -fmessage-length=N was not specified, determine whether this is a
1260 // terminal and, if so, implicitly define -fmessage-length appropriately.
1261 unsigned N
= llvm::sys::Process::StandardErrColumns();
1262 CmdArgs
.push_back(Args
.MakeArgString(llvm::Twine(N
)));
1265 if (const Arg
*A
= Args
.getLastArg(options::OPT_fvisibility_EQ
)) {
1266 CmdArgs
.push_back("-fvisibility");
1267 CmdArgs
.push_back(A
->getValue(Args
));
1270 Args
.AddLastArg(CmdArgs
, options::OPT_fvisibility_inlines_hidden
);
1272 // -fhosted is default.
1273 if (KernelOrKext
|| Args
.hasFlag(options::OPT_ffreestanding
,
1274 options::OPT_fhosted
,
1276 CmdArgs
.push_back("-ffreestanding");
1278 // Forward -f (flag) options which we can pass directly.
1279 Args
.AddLastArg(CmdArgs
, options::OPT_fcatch_undefined_behavior
);
1280 Args
.AddLastArg(CmdArgs
, options::OPT_femit_all_decls
);
1281 Args
.AddLastArg(CmdArgs
, options::OPT_fheinous_gnu_extensions
);
1282 Args
.AddLastArg(CmdArgs
, options::OPT_flimit_debug_info
);
1284 // -flax-vector-conversions is default.
1285 if (!Args
.hasFlag(options::OPT_flax_vector_conversions
,
1286 options::OPT_fno_lax_vector_conversions
))
1287 CmdArgs
.push_back("-fno-lax-vector-conversions");
1289 // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only
1290 // takes precedence.
1291 const Arg
*GCArg
= Args
.getLastArg(options::OPT_fobjc_gc_only
);
1293 GCArg
= Args
.getLastArg(options::OPT_fobjc_gc
);
1295 if (getToolChain().SupportsObjCGC()) {
1296 GCArg
->render(Args
, CmdArgs
);
1298 // FIXME: We should move this to a hard error.
1299 D
.Diag(clang::diag::warn_drv_objc_gc_unsupported
)
1300 << GCArg
->getAsString(Args
);
1304 if (Args
.getLastArg(options::OPT_fapple_kext
))
1305 CmdArgs
.push_back("-fapple-kext");
1307 Args
.AddLastArg(CmdArgs
, options::OPT_fno_show_column
);
1308 Args
.AddLastArg(CmdArgs
, options::OPT_fobjc_sender_dependent_dispatch
);
1309 Args
.AddLastArg(CmdArgs
, options::OPT_fdiagnostics_print_source_range_info
);
1310 Args
.AddLastArg(CmdArgs
, options::OPT_fdiagnostics_parseable_fixits
);
1311 Args
.AddLastArg(CmdArgs
, options::OPT_ftime_report
);
1312 Args
.AddLastArg(CmdArgs
, options::OPT_ftrapv
);
1314 if (Arg
*A
= Args
.getLastArg(options::OPT_ftrapv_handler_EQ
)) {
1315 CmdArgs
.push_back("-ftrapv-handler");
1316 CmdArgs
.push_back(A
->getValue(Args
));
1319 Args
.AddLastArg(CmdArgs
, options::OPT_fwrapv
);
1320 Args
.AddLastArg(CmdArgs
, options::OPT_fwritable_strings
);
1321 Args
.AddLastArg(CmdArgs
, options::OPT_funroll_loops
);
1323 Args
.AddLastArg(CmdArgs
, options::OPT_pthread
);
1325 // -stack-protector=0 is default.
1326 unsigned StackProtectorLevel
= 0;
1327 if (Arg
*A
= Args
.getLastArg(options::OPT_fno_stack_protector
,
1328 options::OPT_fstack_protector_all
,
1329 options::OPT_fstack_protector
)) {
1330 if (A
->getOption().matches(options::OPT_fstack_protector
))
1331 StackProtectorLevel
= 1;
1332 else if (A
->getOption().matches(options::OPT_fstack_protector_all
))
1333 StackProtectorLevel
= 2;
1335 StackProtectorLevel
= getToolChain().GetDefaultStackProtectorLevel();
1336 if (StackProtectorLevel
) {
1337 CmdArgs
.push_back("-stack-protector");
1338 CmdArgs
.push_back(Args
.MakeArgString(llvm::Twine(StackProtectorLevel
)));
1341 // Forward -f options with positive and negative forms; we translate
1344 if (Args
.hasArg(options::OPT_mkernel
)) {
1345 if (!Args
.hasArg(options::OPT_fapple_kext
))
1346 CmdArgs
.push_back("-fapple-kext");
1347 if (!Args
.hasArg(options::OPT_fbuiltin
))
1348 CmdArgs
.push_back("-fno-builtin");
1350 // -fbuiltin is default.
1351 else if (!Args
.hasFlag(options::OPT_fbuiltin
, options::OPT_fno_builtin
))
1352 CmdArgs
.push_back("-fno-builtin");
1354 if (!Args
.hasFlag(options::OPT_fassume_sane_operator_new
,
1355 options::OPT_fno_assume_sane_operator_new
))
1356 CmdArgs
.push_back("-fno-assume-sane-operator-new");
1358 // -fblocks=0 is default.
1359 if (Args
.hasFlag(options::OPT_fblocks
, options::OPT_fno_blocks
,
1360 getToolChain().IsBlocksDefault())) {
1361 CmdArgs
.push_back("-fblocks");
1364 // -faccess-control is default.
1365 if (Args
.hasFlag(options::OPT_fno_access_control
,
1366 options::OPT_faccess_control
,
1368 CmdArgs
.push_back("-fno-access-control");
1370 // -felide-constructors is the default.
1371 if (Args
.hasFlag(options::OPT_fno_elide_constructors
,
1372 options::OPT_felide_constructors
,
1374 CmdArgs
.push_back("-fno-elide-constructors");
1376 // -fexceptions=0 is default.
1377 if (!KernelOrKext
&&
1378 needsExceptions(Args
, InputType
, getToolChain().getTriple()))
1379 CmdArgs
.push_back("-fexceptions");
1381 if (getToolChain().UseSjLjExceptions())
1382 CmdArgs
.push_back("-fsjlj-exceptions");
1384 // -frtti is default.
1386 !Args
.hasFlag(options::OPT_frtti
, options::OPT_fno_rtti
))
1387 CmdArgs
.push_back("-fno-rtti");
1389 // -fshort-enums=0 is default.
1390 // FIXME: Are there targers where -fshort-enums is on by default ?
1391 if (Args
.hasFlag(options::OPT_fshort_enums
,
1392 options::OPT_fno_short_enums
, false))
1393 CmdArgs
.push_back("-fshort-enums");
1395 // -fsigned-char is default.
1396 if (!Args
.hasFlag(options::OPT_fsigned_char
, options::OPT_funsigned_char
,
1397 isSignedCharDefault(getToolChain().getTriple())))
1398 CmdArgs
.push_back("-fno-signed-char");
1400 // -fthreadsafe-static is default.
1401 if (!Args
.hasFlag(options::OPT_fthreadsafe_statics
,
1402 options::OPT_fno_threadsafe_statics
))
1403 CmdArgs
.push_back("-fno-threadsafe-statics");
1405 // -fuse-cxa-atexit is default.
1407 !Args
.hasFlag(options::OPT_fuse_cxa_atexit
, options::OPT_fno_use_cxa_atexit
,
1408 getToolChain().getTriple().getOS() != llvm::Triple::Cygwin
&&
1409 getToolChain().getTriple().getOS() != llvm::Triple::MinGW32
&&
1410 getToolChain().getTriple().getOS() != llvm::Triple::MinGW64
))
1411 CmdArgs
.push_back("-fno-use-cxa-atexit");
1413 // -fms-extensions=0 is default.
1414 if (Args
.hasFlag(options::OPT_fms_extensions
, options::OPT_fno_ms_extensions
,
1415 getToolChain().getTriple().getOS() == llvm::Triple::Win32
))
1416 CmdArgs
.push_back("-fms-extensions");
1418 // -fmsc-version=1300 is default.
1419 if (Args
.hasFlag(options::OPT_fms_extensions
, options::OPT_fno_ms_extensions
,
1420 getToolChain().getTriple().getOS() == llvm::Triple::Win32
) ||
1421 Args
.hasArg(options::OPT_fmsc_version
)) {
1422 llvm::StringRef msc_ver
= Args
.getLastArgValue(options::OPT_fmsc_version
);
1423 if (msc_ver
.empty())
1424 CmdArgs
.push_back("-fmsc-version=1300");
1426 CmdArgs
.push_back(Args
.MakeArgString("-fmsc-version=" + msc_ver
));
1430 // -fborland-extensions=0 is default.
1431 if (Args
.hasFlag(options::OPT_fborland_extensions
,
1432 options::OPT_fno_borland_extensions
, false))
1433 CmdArgs
.push_back("-fborland-extensions");
1435 // -fgnu-keywords default varies depending on language; only pass if
1437 if (Arg
*A
= Args
.getLastArg(options::OPT_fgnu_keywords
,
1438 options::OPT_fno_gnu_keywords
))
1439 A
->render(Args
, CmdArgs
);
1441 // -fnext-runtime defaults to on Darwin and when rewriting Objective-C, and is
1442 // -the -cc1 default.
1443 bool NeXTRuntimeIsDefault
=
1444 IsRewriter
|| getToolChain().getTriple().getOS() == llvm::Triple::Darwin
;
1445 if (!Args
.hasFlag(options::OPT_fnext_runtime
, options::OPT_fgnu_runtime
,
1446 NeXTRuntimeIsDefault
))
1447 CmdArgs
.push_back("-fgnu-runtime");
1449 // -fobjc-nonfragile-abi=0 is default.
1450 if (types::isObjC(InputType
)) {
1451 // Compute the Objective-C ABI "version" to use. Version numbers are
1452 // slightly confusing for historical reasons:
1453 // 1 - Traditional "fragile" ABI
1454 // 2 - Non-fragile ABI, version 1
1455 // 3 - Non-fragile ABI, version 2
1456 unsigned Version
= 1;
1457 // If -fobjc-abi-version= is present, use that to set the version.
1458 if (Arg
*A
= Args
.getLastArg(options::OPT_fobjc_abi_version_EQ
)) {
1459 if (llvm::StringRef(A
->getValue(Args
)) == "1")
1461 else if (llvm::StringRef(A
->getValue(Args
)) == "2")
1463 else if (llvm::StringRef(A
->getValue(Args
)) == "3")
1466 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
1468 // Otherwise, determine if we are using the non-fragile ABI.
1469 if (Args
.hasFlag(options::OPT_fobjc_nonfragile_abi
,
1470 options::OPT_fno_objc_nonfragile_abi
,
1471 getToolChain().IsObjCNonFragileABIDefault())) {
1472 // Determine the non-fragile ABI version to use.
1473 #ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO
1474 unsigned NonFragileABIVersion
= 1;
1476 unsigned NonFragileABIVersion
= 2;
1479 if (Arg
*A
= Args
.getLastArg(
1480 options::OPT_fobjc_nonfragile_abi_version_EQ
)) {
1481 if (llvm::StringRef(A
->getValue(Args
)) == "1")
1482 NonFragileABIVersion
= 1;
1483 else if (llvm::StringRef(A
->getValue(Args
)) == "2")
1484 NonFragileABIVersion
= 2;
1486 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1487 << A
->getAsString(Args
);
1490 Version
= 1 + NonFragileABIVersion
;
1496 if (Version
== 2 || Version
== 3) {
1497 CmdArgs
.push_back("-fobjc-nonfragile-abi");
1499 // -fobjc-dispatch-method is only relevant with the nonfragile-abi, and
1500 // legacy is the default.
1501 if (!Args
.hasFlag(options::OPT_fobjc_legacy_dispatch
,
1502 options::OPT_fno_objc_legacy_dispatch
,
1503 getToolChain().IsObjCLegacyDispatchDefault())) {
1504 if (getToolChain().UseObjCMixedDispatch())
1505 CmdArgs
.push_back("-fobjc-dispatch-method=mixed");
1507 CmdArgs
.push_back("-fobjc-dispatch-method=non-legacy");
1511 // -fobjc-default-synthesize-properties=0 is default.
1512 if (Args
.hasFlag(options::OPT_fobjc_default_synthesize_properties
,
1513 options::OPT_fno_objc_default_synthesize_properties
,
1514 getToolChain().IsObjCDefaultSynthPropertiesDefault())) {
1515 CmdArgs
.push_back("-fobjc-default-synthesize-properties");
1519 if (!Args
.hasFlag(options::OPT_fassume_sane_operator_new
,
1520 options::OPT_fno_assume_sane_operator_new
))
1521 CmdArgs
.push_back("-fno-assume-sane-operator-new");
1523 // -fconstant-cfstrings is default, and may be subject to argument translation
1525 if (!Args
.hasFlag(options::OPT_fconstant_cfstrings
,
1526 options::OPT_fno_constant_cfstrings
) ||
1527 !Args
.hasFlag(options::OPT_mconstant_cfstrings
,
1528 options::OPT_mno_constant_cfstrings
))
1529 CmdArgs
.push_back("-fno-constant-cfstrings");
1531 // -fshort-wchar default varies depending on platform; only
1532 // pass if specified.
1533 if (Arg
*A
= Args
.getLastArg(options::OPT_fshort_wchar
))
1534 A
->render(Args
, CmdArgs
);
1536 // -fno-pascal-strings is default, only pass non-default. If the tool chain
1537 // happened to translate to -mpascal-strings, we want to back translate here.
1539 // FIXME: This is gross; that translation should be pulled from the
1541 if (Args
.hasFlag(options::OPT_fpascal_strings
,
1542 options::OPT_fno_pascal_strings
,
1544 Args
.hasFlag(options::OPT_mpascal_strings
,
1545 options::OPT_mno_pascal_strings
,
1547 CmdArgs
.push_back("-fpascal-strings");
1549 if (Args
.hasArg(options::OPT_mkernel
) ||
1550 Args
.hasArg(options::OPT_fapple_kext
)) {
1551 if (!Args
.hasArg(options::OPT_fcommon
))
1552 CmdArgs
.push_back("-fno-common");
1554 // -fcommon is default, only pass non-default.
1555 else if (!Args
.hasFlag(options::OPT_fcommon
, options::OPT_fno_common
))
1556 CmdArgs
.push_back("-fno-common");
1558 // -fsigned-bitfields is default, and clang doesn't yet support
1559 // -funsigned-bitfields.
1560 if (!Args
.hasFlag(options::OPT_fsigned_bitfields
,
1561 options::OPT_funsigned_bitfields
))
1562 D
.Diag(clang::diag::warn_drv_clang_unsupported
)
1563 << Args
.getLastArg(options::OPT_funsigned_bitfields
)->getAsString(Args
);
1565 // -fsigned-bitfields is default, and clang doesn't support -fno-for-scope.
1566 if (!Args
.hasFlag(options::OPT_ffor_scope
,
1567 options::OPT_fno_for_scope
))
1568 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1569 << Args
.getLastArg(options::OPT_fno_for_scope
)->getAsString(Args
);
1571 // -fcaret-diagnostics is default.
1572 if (!Args
.hasFlag(options::OPT_fcaret_diagnostics
,
1573 options::OPT_fno_caret_diagnostics
, true))
1574 CmdArgs
.push_back("-fno-caret-diagnostics");
1576 // -fdiagnostics-fixit-info is default, only pass non-default.
1577 if (!Args
.hasFlag(options::OPT_fdiagnostics_fixit_info
,
1578 options::OPT_fno_diagnostics_fixit_info
))
1579 CmdArgs
.push_back("-fno-diagnostics-fixit-info");
1581 // Enable -fdiagnostics-show-option by default.
1582 if (Args
.hasFlag(options::OPT_fdiagnostics_show_option
,
1583 options::OPT_fno_diagnostics_show_option
))
1584 CmdArgs
.push_back("-fdiagnostics-show-option");
1587 Args
.getLastArg(options::OPT_fdiagnostics_show_category_EQ
)) {
1588 CmdArgs
.push_back("-fdiagnostics-show-category");
1589 CmdArgs
.push_back(A
->getValue(Args
));
1592 // Color diagnostics are the default, unless the terminal doesn't support
1594 if (Args
.hasFlag(options::OPT_fcolor_diagnostics
,
1595 options::OPT_fno_color_diagnostics
,
1596 llvm::sys::Process::StandardErrHasColors()))
1597 CmdArgs
.push_back("-fcolor-diagnostics");
1599 if (!Args
.hasFlag(options::OPT_fshow_source_location
,
1600 options::OPT_fno_show_source_location
))
1601 CmdArgs
.push_back("-fno-show-source-location");
1603 if (!Args
.hasFlag(options::OPT_fspell_checking
,
1604 options::OPT_fno_spell_checking
))
1605 CmdArgs
.push_back("-fno-spell-checking");
1608 // Silently ignore -fasm-blocks for now.
1609 (void) Args
.hasFlag(options::OPT_fasm_blocks
, options::OPT_fno_asm_blocks
,
1612 if (Arg
*A
= Args
.getLastArg(options::OPT_fshow_overloads_EQ
))
1613 A
->render(Args
, CmdArgs
);
1615 // -fdollars-in-identifiers default varies depending on platform and
1616 // language; only pass if specified.
1617 if (Arg
*A
= Args
.getLastArg(options::OPT_fdollars_in_identifiers
,
1618 options::OPT_fno_dollars_in_identifiers
)) {
1619 if (A
->getOption().matches(options::OPT_fdollars_in_identifiers
))
1620 CmdArgs
.push_back("-fdollars-in-identifiers");
1622 CmdArgs
.push_back("-fno-dollars-in-identifiers");
1625 // -funit-at-a-time is default, and we don't support -fno-unit-at-a-time for
1626 // practical purposes.
1627 if (Arg
*A
= Args
.getLastArg(options::OPT_funit_at_a_time
,
1628 options::OPT_fno_unit_at_a_time
)) {
1629 if (A
->getOption().matches(options::OPT_fno_unit_at_a_time
))
1630 D
.Diag(clang::diag::warn_drv_clang_unsupported
) << A
->getAsString(Args
);
1633 // Default to -fno-builtin-str{cat,cpy} on Darwin for ARM.
1635 // FIXME: This is disabled until clang -cc1 supports -fno-builtin-foo. PR4941.
1637 if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin
&&
1638 (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
1639 getToolChain().getTriple().getArch() == llvm::Triple::thumb
)) {
1640 if (!Args
.hasArg(options::OPT_fbuiltin_strcat
))
1641 CmdArgs
.push_back("-fno-builtin-strcat");
1642 if (!Args
.hasArg(options::OPT_fbuiltin_strcpy
))
1643 CmdArgs
.push_back("-fno-builtin-strcpy");
1647 if (Arg
*A
= Args
.getLastArg(options::OPT_traditional
,
1648 options::OPT_traditional_cpp
))
1649 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
1651 Args
.AddLastArg(CmdArgs
, options::OPT_dM
);
1652 Args
.AddLastArg(CmdArgs
, options::OPT_dD
);
1654 // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
1656 Args
.AddAllArgValues(CmdArgs
, options::OPT_Xclang
);
1657 for (arg_iterator it
= Args
.filtered_begin(options::OPT_mllvm
),
1658 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
1661 // We translate this by hand to the -cc1 argument, since nightly test uses
1662 // it and developers have been trained to spell it with -mllvm.
1663 if (llvm::StringRef((*it
)->getValue(Args
, 0)) == "-disable-llvm-optzns")
1664 CmdArgs
.push_back("-disable-llvm-optzns");
1666 (*it
)->render(Args
, CmdArgs
);
1669 if (Output
.getType() == types::TY_Dependencies
) {
1670 // Handled with other dependency code.
1671 } else if (Output
.isFilename()) {
1672 CmdArgs
.push_back("-o");
1673 CmdArgs
.push_back(Output
.getFilename());
1675 assert(Output
.isNothing() && "Invalid output.");
1678 for (InputInfoList::const_iterator
1679 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
1680 const InputInfo
&II
= *it
;
1681 CmdArgs
.push_back("-x");
1682 CmdArgs
.push_back(types::getTypeName(II
.getType()));
1683 if (II
.isFilename())
1684 CmdArgs
.push_back(II
.getFilename());
1686 II
.getInputArg().renderAsInput(Args
, CmdArgs
);
1689 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
1691 const char *Exec
= getToolChain().getDriver().getClangProgramPath();
1693 // Optionally embed the -cc1 level arguments into the debug info, for build
1695 if (getToolChain().UseDwarfDebugFlags()) {
1696 ArgStringList OriginalArgs
;
1697 for (ArgList::const_iterator it
= Args
.begin(),
1698 ie
= Args
.end(); it
!= ie
; ++it
)
1699 (*it
)->render(Args
, OriginalArgs
);
1701 llvm::SmallString
<256> Flags
;
1703 for (unsigned i
= 0, e
= OriginalArgs
.size(); i
!= e
; ++i
) {
1705 Flags
+= OriginalArgs
[i
];
1707 CmdArgs
.push_back("-dwarf-debug-flags");
1708 CmdArgs
.push_back(Args
.MakeArgString(Flags
.str()));
1711 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1713 // Explicitly warn that these options are unsupported, even though
1714 // we are allowing compilation to continue.
1715 for (arg_iterator it
= Args
.filtered_begin(options::OPT_pg
),
1716 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
1718 D
.Diag(clang::diag::warn_drv_clang_unsupported
) << (*it
)->getAsString(Args
);
1721 // Claim some arguments which clang supports automatically.
1723 // -fpch-preprocess is used with gcc to add a special marker in the output to
1724 // include the PCH file. Clang's PTH solution is completely transparent, so we
1725 // do not need to deal with it at all.
1726 Args
.ClaimAllArgs(options::OPT_fpch_preprocess
);
1728 // Claim some arguments which clang doesn't support, but we don't
1729 // care to warn the user about.
1730 Args
.ClaimAllArgs(options::OPT_clang_ignored_f_Group
);
1731 Args
.ClaimAllArgs(options::OPT_clang_ignored_m_Group
);
1734 void ClangAs::ConstructJob(Compilation
&C
, const JobAction
&JA
,
1735 const InputInfo
&Output
,
1736 const InputInfoList
&Inputs
,
1737 const ArgList
&Args
,
1738 const char *LinkingOutput
) const {
1739 ArgStringList CmdArgs
;
1741 assert(Inputs
.size() == 1 && "Unexpected number of inputs.");
1742 const InputInfo
&Input
= Inputs
[0];
1744 // Don't warn about "clang -w -c foo.s"
1745 Args
.ClaimAllArgs(options::OPT_w
);
1747 // Invoke ourselves in -cc1as mode.
1749 // FIXME: Implement custom jobs for internal actions.
1750 CmdArgs
.push_back("-cc1as");
1752 // Add the "effective" target triple.
1753 CmdArgs
.push_back("-triple");
1754 std::string TripleStr
= getToolChain().ComputeEffectiveClangTriple(Args
);
1755 CmdArgs
.push_back(Args
.MakeArgString(TripleStr
));
1757 // Set the output mode, we currently only expect to be used as a real
1759 CmdArgs
.push_back("-filetype");
1760 CmdArgs
.push_back("obj");
1762 // At -O0, we use -mrelax-all by default.
1764 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
))
1765 IsOpt
= !A
->getOption().matches(options::OPT_O0
);
1766 if (Args
.hasFlag(options::OPT_mrelax_all
,
1767 options::OPT_mno_relax_all
,
1769 CmdArgs
.push_back("-relax-all");
1771 // FIXME: Add -force_cpusubtype_ALL support, once we have it.
1773 // FIXME: Add -g support, once we have it.
1775 // FIXME: Add -static support, once we have it.
1777 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
1778 options::OPT_Xassembler
);
1780 assert(Output
.isFilename() && "Unexpected lipo output.");
1781 CmdArgs
.push_back("-o");
1782 CmdArgs
.push_back(Output
.getFilename());
1784 assert(Input
.isFilename() && "Invalid input.");
1785 CmdArgs
.push_back(Input
.getFilename());
1787 const char *Exec
= getToolChain().getDriver().getClangProgramPath();
1788 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1791 void gcc::Common::ConstructJob(Compilation
&C
, const JobAction
&JA
,
1792 const InputInfo
&Output
,
1793 const InputInfoList
&Inputs
,
1794 const ArgList
&Args
,
1795 const char *LinkingOutput
) const {
1796 const Driver
&D
= getToolChain().getDriver();
1797 ArgStringList CmdArgs
;
1799 for (ArgList::const_iterator
1800 it
= Args
.begin(), ie
= Args
.end(); it
!= ie
; ++it
) {
1802 if (A
->getOption().hasForwardToGCC()) {
1803 // Don't forward any -g arguments to assembly steps.
1804 if (isa
<AssembleJobAction
>(JA
) &&
1805 A
->getOption().matches(options::OPT_g_Group
))
1808 // It is unfortunate that we have to claim here, as this means
1809 // we will basically never report anything interesting for
1810 // platforms using a generic gcc, even if we are just using gcc
1811 // to get to the assembler.
1813 A
->render(Args
, CmdArgs
);
1817 RenderExtraToolArgs(JA
, CmdArgs
);
1819 // If using a driver driver, force the arch.
1820 const std::string
&Arch
= getToolChain().getArchName();
1821 if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin
) {
1822 CmdArgs
.push_back("-arch");
1824 // FIXME: Remove these special cases.
1825 if (Arch
== "powerpc")
1826 CmdArgs
.push_back("ppc");
1827 else if (Arch
== "powerpc64")
1828 CmdArgs
.push_back("ppc64");
1830 CmdArgs
.push_back(Args
.MakeArgString(Arch
));
1833 // Try to force gcc to match the tool chain we want, if we recognize
1836 // FIXME: The triple class should directly provide the information we want
1838 if (Arch
== "i386" || Arch
== "powerpc")
1839 CmdArgs
.push_back("-m32");
1840 else if (Arch
== "x86_64" || Arch
== "powerpc64")
1841 CmdArgs
.push_back("-m64");
1843 if (Output
.isFilename()) {
1844 CmdArgs
.push_back("-o");
1845 CmdArgs
.push_back(Output
.getFilename());
1847 assert(Output
.isNothing() && "Unexpected output");
1848 CmdArgs
.push_back("-fsyntax-only");
1852 // Only pass -x if gcc will understand it; otherwise hope gcc
1853 // understands the suffix correctly. The main use case this would go
1854 // wrong in is for linker inputs if they happened to have an odd
1855 // suffix; really the only way to get this to happen is a command
1856 // like '-x foobar a.c' which will treat a.c like a linker input.
1858 // FIXME: For the linker case specifically, can we safely convert
1859 // inputs into '-Wl,' options?
1860 for (InputInfoList::const_iterator
1861 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
1862 const InputInfo
&II
= *it
;
1864 // Don't try to pass LLVM or AST inputs to a generic gcc.
1865 if (II
.getType() == types::TY_LLVM_IR
|| II
.getType() == types::TY_LTO_IR
||
1866 II
.getType() == types::TY_LLVM_BC
|| II
.getType() == types::TY_LTO_BC
)
1867 D
.Diag(clang::diag::err_drv_no_linker_llvm_support
)
1868 << getToolChain().getTripleString();
1869 else if (II
.getType() == types::TY_AST
)
1870 D
.Diag(clang::diag::err_drv_no_ast_support
)
1871 << getToolChain().getTripleString();
1873 if (types::canTypeBeUserSpecified(II
.getType())) {
1874 CmdArgs
.push_back("-x");
1875 CmdArgs
.push_back(types::getTypeName(II
.getType()));
1878 if (II
.isFilename())
1879 CmdArgs
.push_back(II
.getFilename());
1881 const Arg
&A
= II
.getInputArg();
1883 // Reverse translate some rewritten options.
1884 if (A
.getOption().matches(options::OPT_Z_reserved_lib_stdcxx
)) {
1885 CmdArgs
.push_back("-lstdc++");
1889 // Don't render as input, we need gcc to do the translations.
1890 A
.render(Args
, CmdArgs
);
1894 const char *GCCName
= getToolChain().getDriver().getCCCGenericGCCName().c_str();
1896 Args
.MakeArgString(getToolChain().GetProgramPath(GCCName
));
1897 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1900 void gcc::Preprocess::RenderExtraToolArgs(const JobAction
&JA
,
1901 ArgStringList
&CmdArgs
) const {
1902 CmdArgs
.push_back("-E");
1905 void gcc::Precompile::RenderExtraToolArgs(const JobAction
&JA
,
1906 ArgStringList
&CmdArgs
) const {
1907 // The type is good enough.
1910 void gcc::Compile::RenderExtraToolArgs(const JobAction
&JA
,
1911 ArgStringList
&CmdArgs
) const {
1912 const Driver
&D
= getToolChain().getDriver();
1914 // If -flto, etc. are present then make sure not to force assembly output.
1915 if (JA
.getType() == types::TY_LLVM_IR
|| JA
.getType() == types::TY_LTO_IR
||
1916 JA
.getType() == types::TY_LLVM_BC
|| JA
.getType() == types::TY_LTO_BC
)
1917 CmdArgs
.push_back("-c");
1919 if (JA
.getType() != types::TY_PP_Asm
)
1920 D
.Diag(clang::diag::err_drv_invalid_gcc_output_type
)
1921 << getTypeName(JA
.getType());
1923 CmdArgs
.push_back("-S");
1927 void gcc::Assemble::RenderExtraToolArgs(const JobAction
&JA
,
1928 ArgStringList
&CmdArgs
) const {
1929 CmdArgs
.push_back("-c");
1932 void gcc::Link::RenderExtraToolArgs(const JobAction
&JA
,
1933 ArgStringList
&CmdArgs
) const {
1934 // The types are (hopefully) good enough.
1937 const char *darwin::CC1::getCC1Name(types::ID Type
) const {
1940 assert(0 && "Unexpected type for Darwin CC1 tool.");
1942 case types::TY_C
: case types::TY_CHeader
:
1943 case types::TY_PP_C
: case types::TY_PP_CHeader
:
1945 case types::TY_ObjC
: case types::TY_ObjCHeader
:
1946 case types::TY_PP_ObjC
: case types::TY_PP_ObjCHeader
:
1948 case types::TY_CXX
: case types::TY_CXXHeader
:
1949 case types::TY_PP_CXX
: case types::TY_PP_CXXHeader
:
1951 case types::TY_ObjCXX
: case types::TY_ObjCXXHeader
:
1952 case types::TY_PP_ObjCXX
: case types::TY_PP_ObjCXXHeader
:
1953 return "cc1objplus";
1957 const char *darwin::CC1::getBaseInputName(const ArgList
&Args
,
1958 const InputInfoList
&Inputs
) {
1959 return Args
.MakeArgString(
1960 llvm::sys::path::filename(Inputs
[0].getBaseInput()));
1963 const char *darwin::CC1::getBaseInputStem(const ArgList
&Args
,
1964 const InputInfoList
&Inputs
) {
1965 const char *Str
= getBaseInputName(Args
, Inputs
);
1967 if (const char *End
= strchr(Str
, '.'))
1968 return Args
.MakeArgString(std::string(Str
, End
));
1974 darwin::CC1::getDependencyFileName(const ArgList
&Args
,
1975 const InputInfoList
&Inputs
) {
1976 // FIXME: Think about this more.
1979 if (Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
)) {
1980 std::string
Str(OutputOpt
->getValue(Args
));
1982 Res
= Str
.substr(0, Str
.rfind('.'));
1984 Res
= darwin::CC1::getBaseInputStem(Args
, Inputs
);
1986 return Args
.MakeArgString(Res
+ ".d");
1989 void darwin::CC1::AddCC1Args(const ArgList
&Args
,
1990 ArgStringList
&CmdArgs
) const {
1991 const Driver
&D
= getToolChain().getDriver();
1993 CheckCodeGenerationOptions(D
, Args
);
1995 // Derived from cc1 spec.
1996 if (!Args
.hasArg(options::OPT_mkernel
) && !Args
.hasArg(options::OPT_static
) &&
1997 !Args
.hasArg(options::OPT_mdynamic_no_pic
))
1998 CmdArgs
.push_back("-fPIC");
2000 if (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
2001 getToolChain().getTriple().getArch() == llvm::Triple::thumb
) {
2002 if (!Args
.hasArg(options::OPT_fbuiltin_strcat
))
2003 CmdArgs
.push_back("-fno-builtin-strcat");
2004 if (!Args
.hasArg(options::OPT_fbuiltin_strcpy
))
2005 CmdArgs
.push_back("-fno-builtin-strcpy");
2008 // gcc has some code here to deal with when no -mmacosx-version-min
2009 // and no -miphoneos-version-min is present, but this never happens
2010 // due to tool chain specific argument translation.
2012 if (Args
.hasArg(options::OPT_g_Flag
) &&
2013 !Args
.hasArg(options::OPT_fno_eliminate_unused_debug_symbols
))
2014 CmdArgs
.push_back("-feliminate-unused-debug-symbols");
2017 void darwin::CC1::AddCC1OptionsArgs(const ArgList
&Args
, ArgStringList
&CmdArgs
,
2018 const InputInfoList
&Inputs
,
2019 const ArgStringList
&OutputArgs
) const {
2020 const Driver
&D
= getToolChain().getDriver();
2022 // Derived from cc1_options spec.
2023 if (Args
.hasArg(options::OPT_fast
) ||
2024 Args
.hasArg(options::OPT_fastf
) ||
2025 Args
.hasArg(options::OPT_fastcp
))
2026 CmdArgs
.push_back("-O3");
2028 if (Arg
*A
= Args
.getLastArg(options::OPT_pg
))
2029 if (Args
.hasArg(options::OPT_fomit_frame_pointer
))
2030 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
2031 << A
->getAsString(Args
) << "-fomit-frame-pointer";
2033 AddCC1Args(Args
, CmdArgs
);
2035 if (!Args
.hasArg(options::OPT_Q
))
2036 CmdArgs
.push_back("-quiet");
2038 CmdArgs
.push_back("-dumpbase");
2039 CmdArgs
.push_back(darwin::CC1::getBaseInputName(Args
, Inputs
));
2041 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Group
);
2043 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Group
);
2044 Args
.AddAllArgs(CmdArgs
, options::OPT_a_Group
);
2046 // FIXME: The goal is to use the user provided -o if that is our
2047 // final output, otherwise to drive from the original input
2048 // name. Find a clean way to go about this.
2049 if ((Args
.hasArg(options::OPT_c
) || Args
.hasArg(options::OPT_S
)) &&
2050 Args
.hasArg(options::OPT_o
)) {
2051 Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
);
2052 CmdArgs
.push_back("-auxbase-strip");
2053 CmdArgs
.push_back(OutputOpt
->getValue(Args
));
2055 CmdArgs
.push_back("-auxbase");
2056 CmdArgs
.push_back(darwin::CC1::getBaseInputStem(Args
, Inputs
));
2059 Args
.AddAllArgs(CmdArgs
, options::OPT_g_Group
);
2061 Args
.AddAllArgs(CmdArgs
, options::OPT_O
);
2062 // FIXME: -Wall is getting some special treatment. Investigate.
2063 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
, options::OPT_pedantic_Group
);
2064 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2065 Args
.AddAllArgs(CmdArgs
, options::OPT_std_EQ
, options::OPT_ansi
,
2066 options::OPT_trigraphs
);
2067 if (!Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
2068 // Honor -std-default.
2069 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
2070 "-std=", /*Joined=*/true);
2073 if (Args
.hasArg(options::OPT_v
))
2074 CmdArgs
.push_back("-version");
2075 if (Args
.hasArg(options::OPT_pg
))
2076 CmdArgs
.push_back("-p");
2077 Args
.AddLastArg(CmdArgs
, options::OPT_p
);
2079 // The driver treats -fsyntax-only specially.
2080 if (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
2081 getToolChain().getTriple().getArch() == llvm::Triple::thumb
) {
2082 // Removes -fbuiltin-str{cat,cpy}; these aren't recognized by cc1 but are
2083 // used to inhibit the default -fno-builtin-str{cat,cpy}.
2085 // FIXME: Should we grow a better way to deal with "removing" args?
2086 for (arg_iterator it
= Args
.filtered_begin(options::OPT_f_Group
,
2087 options::OPT_fsyntax_only
),
2088 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
2089 if (!(*it
)->getOption().matches(options::OPT_fbuiltin_strcat
) &&
2090 !(*it
)->getOption().matches(options::OPT_fbuiltin_strcpy
)) {
2092 (*it
)->render(Args
, CmdArgs
);
2096 Args
.AddAllArgs(CmdArgs
, options::OPT_f_Group
, options::OPT_fsyntax_only
);
2098 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
2099 if (Args
.hasArg(options::OPT_Qn
))
2100 CmdArgs
.push_back("-fno-ident");
2102 // FIXME: This isn't correct.
2103 //Args.AddLastArg(CmdArgs, options::OPT__help)
2104 //Args.AddLastArg(CmdArgs, options::OPT__targetHelp)
2106 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2108 // FIXME: Still don't get what is happening here. Investigate.
2109 Args
.AddAllArgs(CmdArgs
, options::OPT__param
);
2111 if (Args
.hasArg(options::OPT_fmudflap
) ||
2112 Args
.hasArg(options::OPT_fmudflapth
)) {
2113 CmdArgs
.push_back("-fno-builtin");
2114 CmdArgs
.push_back("-fno-merge-constants");
2117 if (Args
.hasArg(options::OPT_coverage
)) {
2118 CmdArgs
.push_back("-fprofile-arcs");
2119 CmdArgs
.push_back("-ftest-coverage");
2122 if (types::isCXX(Inputs
[0].getType()))
2123 CmdArgs
.push_back("-D__private_extern__=extern");
2126 void darwin::CC1::AddCPPOptionsArgs(const ArgList
&Args
, ArgStringList
&CmdArgs
,
2127 const InputInfoList
&Inputs
,
2128 const ArgStringList
&OutputArgs
) const {
2129 // Derived from cpp_options
2130 AddCPPUniqueOptionsArgs(Args
, CmdArgs
, Inputs
);
2132 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2134 AddCC1Args(Args
, CmdArgs
);
2136 // NOTE: The code below has some commonality with cpp_options, but
2137 // in classic gcc style ends up sending things in different
2138 // orders. This may be a good merge candidate once we drop pedantic
2141 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Group
);
2142 Args
.AddAllArgs(CmdArgs
, options::OPT_std_EQ
, options::OPT_ansi
,
2143 options::OPT_trigraphs
);
2144 if (!Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
2145 // Honor -std-default.
2146 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
2147 "-std=", /*Joined=*/true);
2149 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
, options::OPT_pedantic_Group
);
2150 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2152 // The driver treats -fsyntax-only specially.
2153 Args
.AddAllArgs(CmdArgs
, options::OPT_f_Group
, options::OPT_fsyntax_only
);
2155 if (Args
.hasArg(options::OPT_g_Group
) && !Args
.hasArg(options::OPT_g0
) &&
2156 !Args
.hasArg(options::OPT_fno_working_directory
))
2157 CmdArgs
.push_back("-fworking-directory");
2159 Args
.AddAllArgs(CmdArgs
, options::OPT_O
);
2160 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
2161 if (Args
.hasArg(options::OPT_save_temps
))
2162 CmdArgs
.push_back("-fpch-preprocess");
2165 void darwin::CC1::AddCPPUniqueOptionsArgs(const ArgList
&Args
,
2166 ArgStringList
&CmdArgs
,
2167 const InputInfoList
&Inputs
) const {
2168 const Driver
&D
= getToolChain().getDriver();
2170 CheckPreprocessingOptions(D
, Args
);
2172 // Derived from cpp_unique_options.
2173 // -{C,CC} only with -E is checked in CheckPreprocessingOptions().
2174 Args
.AddLastArg(CmdArgs
, options::OPT_C
);
2175 Args
.AddLastArg(CmdArgs
, options::OPT_CC
);
2176 if (!Args
.hasArg(options::OPT_Q
))
2177 CmdArgs
.push_back("-quiet");
2178 Args
.AddAllArgs(CmdArgs
, options::OPT_nostdinc
);
2179 Args
.AddAllArgs(CmdArgs
, options::OPT_nostdincxx
);
2180 Args
.AddLastArg(CmdArgs
, options::OPT_v
);
2181 Args
.AddAllArgs(CmdArgs
, options::OPT_I_Group
, options::OPT_F
);
2182 Args
.AddLastArg(CmdArgs
, options::OPT_P
);
2184 // FIXME: Handle %I properly.
2185 if (getToolChain().getArchName() == "x86_64") {
2186 CmdArgs
.push_back("-imultilib");
2187 CmdArgs
.push_back("x86_64");
2190 if (Args
.hasArg(options::OPT_MD
)) {
2191 CmdArgs
.push_back("-MD");
2192 CmdArgs
.push_back(darwin::CC1::getDependencyFileName(Args
, Inputs
));
2195 if (Args
.hasArg(options::OPT_MMD
)) {
2196 CmdArgs
.push_back("-MMD");
2197 CmdArgs
.push_back(darwin::CC1::getDependencyFileName(Args
, Inputs
));
2200 Args
.AddLastArg(CmdArgs
, options::OPT_M
);
2201 Args
.AddLastArg(CmdArgs
, options::OPT_MM
);
2202 Args
.AddAllArgs(CmdArgs
, options::OPT_MF
);
2203 Args
.AddLastArg(CmdArgs
, options::OPT_MG
);
2204 Args
.AddLastArg(CmdArgs
, options::OPT_MP
);
2205 Args
.AddAllArgs(CmdArgs
, options::OPT_MQ
);
2206 Args
.AddAllArgs(CmdArgs
, options::OPT_MT
);
2207 if (!Args
.hasArg(options::OPT_M
) && !Args
.hasArg(options::OPT_MM
) &&
2208 (Args
.hasArg(options::OPT_MD
) || Args
.hasArg(options::OPT_MMD
))) {
2209 if (Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
)) {
2210 CmdArgs
.push_back("-MQ");
2211 CmdArgs
.push_back(OutputOpt
->getValue(Args
));
2215 Args
.AddLastArg(CmdArgs
, options::OPT_remap
);
2216 if (Args
.hasArg(options::OPT_g3
))
2217 CmdArgs
.push_back("-dD");
2218 Args
.AddLastArg(CmdArgs
, options::OPT_H
);
2220 AddCPPArgs(Args
, CmdArgs
);
2222 Args
.AddAllArgs(CmdArgs
, options::OPT_D
, options::OPT_U
, options::OPT_A
);
2223 Args
.AddAllArgs(CmdArgs
, options::OPT_i_Group
);
2225 for (InputInfoList::const_iterator
2226 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2227 const InputInfo
&II
= *it
;
2229 CmdArgs
.push_back(II
.getFilename());
2232 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wp_COMMA
,
2233 options::OPT_Xpreprocessor
);
2235 if (Args
.hasArg(options::OPT_fmudflap
)) {
2236 CmdArgs
.push_back("-D_MUDFLAP");
2237 CmdArgs
.push_back("-include");
2238 CmdArgs
.push_back("mf-runtime.h");
2241 if (Args
.hasArg(options::OPT_fmudflapth
)) {
2242 CmdArgs
.push_back("-D_MUDFLAP");
2243 CmdArgs
.push_back("-D_MUDFLAPTH");
2244 CmdArgs
.push_back("-include");
2245 CmdArgs
.push_back("mf-runtime.h");
2249 void darwin::CC1::AddCPPArgs(const ArgList
&Args
,
2250 ArgStringList
&CmdArgs
) const {
2251 // Derived from cpp spec.
2253 if (Args
.hasArg(options::OPT_static
)) {
2254 // The gcc spec is broken here, it refers to dynamic but
2255 // that has been translated. Start by being bug compatible.
2257 // if (!Args.hasArg(arglist.parser.dynamicOption))
2258 CmdArgs
.push_back("-D__STATIC__");
2260 CmdArgs
.push_back("-D__DYNAMIC__");
2262 if (Args
.hasArg(options::OPT_pthread
))
2263 CmdArgs
.push_back("-D_REENTRANT");
2266 void darwin::Preprocess::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2267 const InputInfo
&Output
,
2268 const InputInfoList
&Inputs
,
2269 const ArgList
&Args
,
2270 const char *LinkingOutput
) const {
2271 ArgStringList CmdArgs
;
2273 assert(Inputs
.size() == 1 && "Unexpected number of inputs!");
2275 CmdArgs
.push_back("-E");
2277 if (Args
.hasArg(options::OPT_traditional
) ||
2278 Args
.hasArg(options::OPT_traditional_cpp
))
2279 CmdArgs
.push_back("-traditional-cpp");
2281 ArgStringList OutputArgs
;
2282 assert(Output
.isFilename() && "Unexpected CC1 output.");
2283 OutputArgs
.push_back("-o");
2284 OutputArgs
.push_back(Output
.getFilename());
2286 if (Args
.hasArg(options::OPT_E
)) {
2287 AddCPPOptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2289 AddCPPOptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2290 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2293 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Group
);
2295 const char *CC1Name
= getCC1Name(Inputs
[0].getType());
2297 Args
.MakeArgString(getToolChain().GetProgramPath(CC1Name
));
2298 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2301 void darwin::Compile::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2302 const InputInfo
&Output
,
2303 const InputInfoList
&Inputs
,
2304 const ArgList
&Args
,
2305 const char *LinkingOutput
) const {
2306 const Driver
&D
= getToolChain().getDriver();
2307 ArgStringList CmdArgs
;
2309 assert(Inputs
.size() == 1 && "Unexpected number of inputs!");
2311 types::ID InputType
= Inputs
[0].getType();
2313 if ((A
= Args
.getLastArg(options::OPT_traditional
)))
2314 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
2315 << A
->getAsString(Args
) << "-E";
2317 if (JA
.getType() == types::TY_LLVM_IR
||
2318 JA
.getType() == types::TY_LTO_IR
)
2319 CmdArgs
.push_back("-emit-llvm");
2320 else if (JA
.getType() == types::TY_LLVM_BC
||
2321 JA
.getType() == types::TY_LTO_BC
)
2322 CmdArgs
.push_back("-emit-llvm-bc");
2323 else if (Output
.getType() == types::TY_AST
)
2324 D
.Diag(clang::diag::err_drv_no_ast_support
)
2325 << getToolChain().getTripleString();
2326 else if (JA
.getType() != types::TY_PP_Asm
&&
2327 JA
.getType() != types::TY_PCH
)
2328 D
.Diag(clang::diag::err_drv_invalid_gcc_output_type
)
2329 << getTypeName(JA
.getType());
2331 ArgStringList OutputArgs
;
2332 if (Output
.getType() != types::TY_PCH
) {
2333 OutputArgs
.push_back("-o");
2334 if (Output
.isNothing())
2335 OutputArgs
.push_back("/dev/null");
2337 OutputArgs
.push_back(Output
.getFilename());
2340 // There is no need for this level of compatibility, but it makes
2342 bool OutputArgsEarly
= (Args
.hasArg(options::OPT_fsyntax_only
) ||
2343 Args
.hasArg(options::OPT_S
));
2345 if (types::getPreprocessedType(InputType
) != types::TY_INVALID
) {
2346 AddCPPUniqueOptionsArgs(Args
, CmdArgs
, Inputs
);
2347 if (OutputArgsEarly
) {
2348 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2350 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2351 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2354 CmdArgs
.push_back("-fpreprocessed");
2356 for (InputInfoList::const_iterator
2357 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2358 const InputInfo
&II
= *it
;
2360 // Reject AST inputs.
2361 if (II
.getType() == types::TY_AST
) {
2362 D
.Diag(clang::diag::err_drv_no_ast_support
)
2363 << getToolChain().getTripleString();
2367 CmdArgs
.push_back(II
.getFilename());
2370 if (OutputArgsEarly
) {
2371 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2373 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2374 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2378 if (Output
.getType() == types::TY_PCH
) {
2379 assert(Output
.isFilename() && "Invalid PCH output.");
2381 CmdArgs
.push_back("-o");
2382 // NOTE: gcc uses a temp .s file for this, but there doesn't seem
2383 // to be a good reason.
2384 CmdArgs
.push_back("/dev/null");
2386 CmdArgs
.push_back("--output-pch=");
2387 CmdArgs
.push_back(Output
.getFilename());
2390 const char *CC1Name
= getCC1Name(Inputs
[0].getType());
2392 Args
.MakeArgString(getToolChain().GetProgramPath(CC1Name
));
2393 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2396 void darwin::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2397 const InputInfo
&Output
,
2398 const InputInfoList
&Inputs
,
2399 const ArgList
&Args
,
2400 const char *LinkingOutput
) const {
2401 ArgStringList CmdArgs
;
2403 assert(Inputs
.size() == 1 && "Unexpected number of inputs.");
2404 const InputInfo
&Input
= Inputs
[0];
2406 // Bit of a hack, this is only used for original inputs.
2408 // FIXME: This is broken for preprocessed .s inputs.
2409 if (Input
.isFilename() &&
2410 strcmp(Input
.getFilename(), Input
.getBaseInput()) == 0) {
2411 if (Args
.hasArg(options::OPT_gstabs
))
2412 CmdArgs
.push_back("--gstabs");
2413 else if (Args
.hasArg(options::OPT_g_Group
))
2414 CmdArgs
.push_back("--gdwarf2");
2417 // Derived from asm spec.
2418 AddDarwinArch(Args
, CmdArgs
);
2420 // Use -force_cpusubtype_ALL on x86 by default.
2421 if (getToolChain().getTriple().getArch() == llvm::Triple::x86
||
2422 getToolChain().getTriple().getArch() == llvm::Triple::x86_64
||
2423 Args
.hasArg(options::OPT_force__cpusubtype__ALL
))
2424 CmdArgs
.push_back("-force_cpusubtype_ALL");
2426 if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64
&&
2427 (Args
.hasArg(options::OPT_mkernel
) ||
2428 Args
.hasArg(options::OPT_static
) ||
2429 Args
.hasArg(options::OPT_fapple_kext
)))
2430 CmdArgs
.push_back("-static");
2432 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2433 options::OPT_Xassembler
);
2435 assert(Output
.isFilename() && "Unexpected lipo output.");
2436 CmdArgs
.push_back("-o");
2437 CmdArgs
.push_back(Output
.getFilename());
2439 assert(Input
.isFilename() && "Invalid input.");
2440 CmdArgs
.push_back(Input
.getFilename());
2442 // asm_final spec is empty.
2445 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
2446 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2449 void darwin::DarwinTool::AddDarwinArch(const ArgList
&Args
,
2450 ArgStringList
&CmdArgs
) const {
2451 llvm::StringRef ArchName
= getDarwinToolChain().getDarwinArchName(Args
);
2453 // Derived from darwin_arch spec.
2454 CmdArgs
.push_back("-arch");
2455 CmdArgs
.push_back(Args
.MakeArgString(ArchName
));
2457 // FIXME: Is this needed anymore?
2458 if (ArchName
== "arm")
2459 CmdArgs
.push_back("-force_cpusubtype_ALL");
2462 void darwin::Link::AddLinkArgs(Compilation
&C
,
2463 const ArgList
&Args
,
2464 ArgStringList
&CmdArgs
) const {
2465 const Driver
&D
= getToolChain().getDriver();
2467 unsigned Version
[3] = { 0, 0, 0 };
2468 if (Arg
*A
= Args
.getLastArg(options::OPT_mlinker_version_EQ
)) {
2470 if (!Driver::GetReleaseVersion(A
->getValue(Args
), Version
[0],
2471 Version
[1], Version
[2], HadExtra
) ||
2473 D
.Diag(clang::diag::err_drv_invalid_version_number
)
2474 << A
->getAsString(Args
);
2477 // Newer linkers support -demangle, pass it if supported and not disabled by
2480 // FIXME: We temporarily avoid passing -demangle to any iOS linker, because
2481 // unfortunately we can't be guaranteed that the linker version used there
2482 // will match the linker version detected at configure time. We need the
2483 // universal driver.
2484 if (Version
[0] >= 100 && !Args
.hasArg(options::OPT_Z_Xlinker__no_demangle
) &&
2485 !getDarwinToolChain().isTargetIPhoneOS()) {
2486 // Don't pass -demangle to ld_classic.
2488 // FIXME: This is a temporary workaround, ld should be handling this.
2489 bool UsesLdClassic
= (getToolChain().getArch() == llvm::Triple::x86
&&
2490 Args
.hasArg(options::OPT_static
));
2491 if (getToolChain().getArch() == llvm::Triple::x86
) {
2492 for (arg_iterator it
= Args
.filtered_begin(options::OPT_Xlinker
,
2493 options::OPT_Wl_COMMA
),
2494 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
2496 for (unsigned i
= 0, e
= A
->getNumValues(); i
!= e
; ++i
)
2497 if (llvm::StringRef(A
->getValue(Args
, i
)) == "-kext")
2498 UsesLdClassic
= true;
2502 CmdArgs
.push_back("-demangle");
2505 // Derived from the "link" spec.
2506 Args
.AddAllArgs(CmdArgs
, options::OPT_static
);
2507 if (!Args
.hasArg(options::OPT_static
))
2508 CmdArgs
.push_back("-dynamic");
2509 if (Args
.hasArg(options::OPT_fgnu_runtime
)) {
2510 // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu
2511 // here. How do we wish to handle such things?
2514 if (!Args
.hasArg(options::OPT_dynamiclib
)) {
2515 AddDarwinArch(Args
, CmdArgs
);
2516 // FIXME: Why do this only on this path?
2517 Args
.AddLastArg(CmdArgs
, options::OPT_force__cpusubtype__ALL
);
2519 Args
.AddLastArg(CmdArgs
, options::OPT_bundle
);
2520 Args
.AddAllArgs(CmdArgs
, options::OPT_bundle__loader
);
2521 Args
.AddAllArgs(CmdArgs
, options::OPT_client__name
);
2524 if ((A
= Args
.getLastArg(options::OPT_compatibility__version
)) ||
2525 (A
= Args
.getLastArg(options::OPT_current__version
)) ||
2526 (A
= Args
.getLastArg(options::OPT_install__name
)))
2527 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
2528 << A
->getAsString(Args
) << "-dynamiclib";
2530 Args
.AddLastArg(CmdArgs
, options::OPT_force__flat__namespace
);
2531 Args
.AddLastArg(CmdArgs
, options::OPT_keep__private__externs
);
2532 Args
.AddLastArg(CmdArgs
, options::OPT_private__bundle
);
2534 CmdArgs
.push_back("-dylib");
2537 if ((A
= Args
.getLastArg(options::OPT_bundle
)) ||
2538 (A
= Args
.getLastArg(options::OPT_bundle__loader
)) ||
2539 (A
= Args
.getLastArg(options::OPT_client__name
)) ||
2540 (A
= Args
.getLastArg(options::OPT_force__flat__namespace
)) ||
2541 (A
= Args
.getLastArg(options::OPT_keep__private__externs
)) ||
2542 (A
= Args
.getLastArg(options::OPT_private__bundle
)))
2543 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
2544 << A
->getAsString(Args
) << "-dynamiclib";
2546 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_compatibility__version
,
2547 "-dylib_compatibility_version");
2548 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_current__version
,
2549 "-dylib_current_version");
2551 AddDarwinArch(Args
, CmdArgs
);
2553 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_install__name
,
2554 "-dylib_install_name");
2557 Args
.AddLastArg(CmdArgs
, options::OPT_all__load
);
2558 Args
.AddAllArgs(CmdArgs
, options::OPT_allowable__client
);
2559 Args
.AddLastArg(CmdArgs
, options::OPT_bind__at__load
);
2560 if (getDarwinToolChain().isTargetIPhoneOS())
2561 Args
.AddLastArg(CmdArgs
, options::OPT_arch__errors__fatal
);
2562 Args
.AddLastArg(CmdArgs
, options::OPT_dead__strip
);
2563 Args
.AddLastArg(CmdArgs
, options::OPT_no__dead__strip__inits__and__terms
);
2564 Args
.AddAllArgs(CmdArgs
, options::OPT_dylib__file
);
2565 Args
.AddLastArg(CmdArgs
, options::OPT_dynamic
);
2566 Args
.AddAllArgs(CmdArgs
, options::OPT_exported__symbols__list
);
2567 Args
.AddLastArg(CmdArgs
, options::OPT_flat__namespace
);
2568 Args
.AddAllArgs(CmdArgs
, options::OPT_headerpad__max__install__names
);
2569 Args
.AddAllArgs(CmdArgs
, options::OPT_image__base
);
2570 Args
.AddAllArgs(CmdArgs
, options::OPT_init
);
2572 // Adding all arguments doesn't make sense here but this is what gcc does. One
2573 // of this should always be present thanks to argument translation.
2574 assert((Args
.hasArg(options::OPT_mmacosx_version_min_EQ
) ||
2575 Args
.hasArg(options::OPT_miphoneos_version_min_EQ
)) &&
2576 "Missing version argument (lost in translation)?");
2577 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_mmacosx_version_min_EQ
,
2578 "-macosx_version_min");
2579 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_miphoneos_version_min_EQ
,
2580 "-iphoneos_version_min");
2581 Args
.AddLastArg(CmdArgs
, options::OPT_nomultidefs
);
2582 Args
.AddLastArg(CmdArgs
, options::OPT_multi__module
);
2583 Args
.AddLastArg(CmdArgs
, options::OPT_single__module
);
2584 Args
.AddAllArgs(CmdArgs
, options::OPT_multiply__defined
);
2585 Args
.AddAllArgs(CmdArgs
, options::OPT_multiply__defined__unused
);
2587 if (const Arg
*A
= Args
.getLastArg(options::OPT_fpie
, options::OPT_fPIE
,
2588 options::OPT_fno_pie
,
2589 options::OPT_fno_PIE
)) {
2590 if (A
->getOption().matches(options::OPT_fpie
) ||
2591 A
->getOption().matches(options::OPT_fPIE
))
2592 CmdArgs
.push_back("-pie");
2594 CmdArgs
.push_back("-no_pie");
2597 Args
.AddLastArg(CmdArgs
, options::OPT_prebind
);
2598 Args
.AddLastArg(CmdArgs
, options::OPT_noprebind
);
2599 Args
.AddLastArg(CmdArgs
, options::OPT_nofixprebinding
);
2600 Args
.AddLastArg(CmdArgs
, options::OPT_prebind__all__twolevel__modules
);
2601 Args
.AddLastArg(CmdArgs
, options::OPT_read__only__relocs
);
2602 Args
.AddAllArgs(CmdArgs
, options::OPT_sectcreate
);
2603 Args
.AddAllArgs(CmdArgs
, options::OPT_sectorder
);
2604 Args
.AddAllArgs(CmdArgs
, options::OPT_seg1addr
);
2605 Args
.AddAllArgs(CmdArgs
, options::OPT_segprot
);
2606 Args
.AddAllArgs(CmdArgs
, options::OPT_segaddr
);
2607 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__only__addr
);
2608 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__write__addr
);
2609 Args
.AddAllArgs(CmdArgs
, options::OPT_seg__addr__table
);
2610 Args
.AddAllArgs(CmdArgs
, options::OPT_seg__addr__table__filename
);
2611 Args
.AddAllArgs(CmdArgs
, options::OPT_sub__library
);
2612 Args
.AddAllArgs(CmdArgs
, options::OPT_sub__umbrella
);
2614 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_isysroot
, "-syslibroot");
2615 if (getDarwinToolChain().isTargetIPhoneOS()) {
2616 if (!Args
.hasArg(options::OPT_isysroot
)) {
2617 CmdArgs
.push_back("-syslibroot");
2618 CmdArgs
.push_back("/Developer/SDKs/Extra");
2622 Args
.AddLastArg(CmdArgs
, options::OPT_twolevel__namespace
);
2623 Args
.AddLastArg(CmdArgs
, options::OPT_twolevel__namespace__hints
);
2624 Args
.AddAllArgs(CmdArgs
, options::OPT_umbrella
);
2625 Args
.AddAllArgs(CmdArgs
, options::OPT_undefined
);
2626 Args
.AddAllArgs(CmdArgs
, options::OPT_unexported__symbols__list
);
2627 Args
.AddAllArgs(CmdArgs
, options::OPT_weak__reference__mismatches
);
2628 Args
.AddLastArg(CmdArgs
, options::OPT_X_Flag
);
2629 Args
.AddAllArgs(CmdArgs
, options::OPT_y
);
2630 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2631 Args
.AddAllArgs(CmdArgs
, options::OPT_pagezero__size
);
2632 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__
);
2633 Args
.AddLastArg(CmdArgs
, options::OPT_seglinkedit
);
2634 Args
.AddLastArg(CmdArgs
, options::OPT_noseglinkedit
);
2635 Args
.AddAllArgs(CmdArgs
, options::OPT_sectalign
);
2636 Args
.AddAllArgs(CmdArgs
, options::OPT_sectobjectsymbols
);
2637 Args
.AddAllArgs(CmdArgs
, options::OPT_segcreate
);
2638 Args
.AddLastArg(CmdArgs
, options::OPT_whyload
);
2639 Args
.AddLastArg(CmdArgs
, options::OPT_whatsloaded
);
2640 Args
.AddAllArgs(CmdArgs
, options::OPT_dylinker__install__name
);
2641 Args
.AddLastArg(CmdArgs
, options::OPT_dylinker
);
2642 Args
.AddLastArg(CmdArgs
, options::OPT_Mach
);
2645 void darwin::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2646 const InputInfo
&Output
,
2647 const InputInfoList
&Inputs
,
2648 const ArgList
&Args
,
2649 const char *LinkingOutput
) const {
2650 assert(Output
.getType() == types::TY_Image
&& "Invalid linker output type.");
2652 // The logic here is derived from gcc's behavior; most of which
2653 // comes from specs (starting with link_command). Consult gcc for
2654 // more information.
2655 ArgStringList CmdArgs
;
2657 // I'm not sure why this particular decomposition exists in gcc, but
2658 // we follow suite for ease of comparison.
2659 AddLinkArgs(C
, Args
, CmdArgs
);
2661 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Flag
);
2662 Args
.AddAllArgs(CmdArgs
, options::OPT_s
);
2663 Args
.AddAllArgs(CmdArgs
, options::OPT_t
);
2664 Args
.AddAllArgs(CmdArgs
, options::OPT_Z_Flag
);
2665 Args
.AddAllArgs(CmdArgs
, options::OPT_u_Group
);
2666 Args
.AddAllArgs(CmdArgs
, options::OPT_A
);
2667 Args
.AddLastArg(CmdArgs
, options::OPT_e
);
2668 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Separate
);
2669 Args
.AddAllArgs(CmdArgs
, options::OPT_r
);
2671 // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading
2672 // members of static archive libraries which implement Objective-C classes or
2674 if (Args
.hasArg(options::OPT_ObjC
) || Args
.hasArg(options::OPT_ObjCXX
))
2675 CmdArgs
.push_back("-ObjC");
2677 CmdArgs
.push_back("-o");
2678 CmdArgs
.push_back(Output
.getFilename());
2680 if (!Args
.hasArg(options::OPT_A
) &&
2681 !Args
.hasArg(options::OPT_nostdlib
) &&
2682 !Args
.hasArg(options::OPT_nostartfiles
)) {
2683 // Derived from startfile spec.
2684 if (Args
.hasArg(options::OPT_dynamiclib
)) {
2685 // Derived from darwin_dylib1 spec.
2686 if (getDarwinToolChain().isTargetIPhoneOS()) {
2687 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2688 CmdArgs
.push_back("-ldylib1.o");
2690 if (getDarwinToolChain().isMacosxVersionLT(10, 5))
2691 CmdArgs
.push_back("-ldylib1.o");
2692 else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2693 CmdArgs
.push_back("-ldylib1.10.5.o");
2696 if (Args
.hasArg(options::OPT_bundle
)) {
2697 if (!Args
.hasArg(options::OPT_static
)) {
2698 // Derived from darwin_bundle1 spec.
2699 if (getDarwinToolChain().isTargetIPhoneOS()) {
2700 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2701 CmdArgs
.push_back("-lbundle1.o");
2703 if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2704 CmdArgs
.push_back("-lbundle1.o");
2708 if (Args
.hasArg(options::OPT_pg
)) {
2709 if (Args
.hasArg(options::OPT_static
) ||
2710 Args
.hasArg(options::OPT_object
) ||
2711 Args
.hasArg(options::OPT_preload
)) {
2712 CmdArgs
.push_back("-lgcrt0.o");
2714 CmdArgs
.push_back("-lgcrt1.o");
2716 // darwin_crt2 spec is empty.
2719 if (Args
.hasArg(options::OPT_static
) ||
2720 Args
.hasArg(options::OPT_object
) ||
2721 Args
.hasArg(options::OPT_preload
)) {
2722 CmdArgs
.push_back("-lcrt0.o");
2724 // Derived from darwin_crt1 spec.
2725 if (getDarwinToolChain().isTargetIPhoneOS()) {
2726 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2727 CmdArgs
.push_back("-lcrt1.o");
2729 CmdArgs
.push_back("-lcrt1.3.1.o");
2731 if (getDarwinToolChain().isMacosxVersionLT(10, 5))
2732 CmdArgs
.push_back("-lcrt1.o");
2733 else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2734 CmdArgs
.push_back("-lcrt1.10.5.o");
2736 CmdArgs
.push_back("-lcrt1.10.6.o");
2738 // darwin_crt2 spec is empty.
2745 if (!getDarwinToolChain().isTargetIPhoneOS() &&
2746 Args
.hasArg(options::OPT_shared_libgcc
) &&
2747 getDarwinToolChain().isMacosxVersionLT(10, 5)) {
2749 Args
.MakeArgString(getToolChain().GetFilePath("crt3.o"));
2750 CmdArgs
.push_back(Str
);
2754 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
2756 if (Args
.hasArg(options::OPT_fopenmp
))
2757 // This is more complicated in gcc...
2758 CmdArgs
.push_back("-lgomp");
2760 getDarwinToolChain().AddLinkSearchPathArgs(Args
, CmdArgs
);
2762 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
2764 if (LinkingOutput
) {
2765 CmdArgs
.push_back("-arch_multiple");
2766 CmdArgs
.push_back("-final_output");
2767 CmdArgs
.push_back(LinkingOutput
);
2770 if (Args
.hasArg(options::OPT_fprofile_arcs
) ||
2771 Args
.hasArg(options::OPT_fprofile_generate
) ||
2772 Args
.hasArg(options::OPT_fcreate_profile
) ||
2773 Args
.hasArg(options::OPT_coverage
))
2774 CmdArgs
.push_back("-lgcov");
2776 if (Args
.hasArg(options::OPT_fnested_functions
))
2777 CmdArgs
.push_back("-allow_stack_execute");
2779 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2780 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
2781 if (getToolChain().getDriver().CCCIsCXX
)
2782 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
2784 // link_ssp spec is empty.
2786 // Let the tool chain choose which runtime library to link.
2787 getDarwinToolChain().AddLinkRuntimeLibArgs(Args
, CmdArgs
);
2790 if (!Args
.hasArg(options::OPT_A
) &&
2791 !Args
.hasArg(options::OPT_nostdlib
) &&
2792 !Args
.hasArg(options::OPT_nostartfiles
)) {
2793 // endfile_spec is empty.
2796 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
2797 Args
.AddAllArgs(CmdArgs
, options::OPT_F
);
2800 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
2801 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2804 void darwin::Lipo::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2805 const InputInfo
&Output
,
2806 const InputInfoList
&Inputs
,
2807 const ArgList
&Args
,
2808 const char *LinkingOutput
) const {
2809 ArgStringList CmdArgs
;
2811 CmdArgs
.push_back("-create");
2812 assert(Output
.isFilename() && "Unexpected lipo output.");
2814 CmdArgs
.push_back("-output");
2815 CmdArgs
.push_back(Output
.getFilename());
2817 for (InputInfoList::const_iterator
2818 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2819 const InputInfo
&II
= *it
;
2820 assert(II
.isFilename() && "Unexpected lipo input.");
2821 CmdArgs
.push_back(II
.getFilename());
2824 Args
.MakeArgString(getToolChain().GetProgramPath("lipo"));
2825 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2828 void darwin::Dsymutil::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2829 const InputInfo
&Output
,
2830 const InputInfoList
&Inputs
,
2831 const ArgList
&Args
,
2832 const char *LinkingOutput
) const {
2833 ArgStringList CmdArgs
;
2835 assert(Inputs
.size() == 1 && "Unable to handle multiple inputs.");
2836 const InputInfo
&Input
= Inputs
[0];
2837 assert(Input
.isFilename() && "Unexpected dsymutil input.");
2838 CmdArgs
.push_back(Input
.getFilename());
2840 CmdArgs
.push_back("-o");
2841 CmdArgs
.push_back(Output
.getFilename());
2844 Args
.MakeArgString(getToolChain().GetProgramPath("dsymutil"));
2845 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2848 void auroraux::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2849 const InputInfo
&Output
,
2850 const InputInfoList
&Inputs
,
2851 const ArgList
&Args
,
2852 const char *LinkingOutput
) const {
2853 ArgStringList CmdArgs
;
2855 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2856 options::OPT_Xassembler
);
2858 CmdArgs
.push_back("-o");
2859 CmdArgs
.push_back(Output
.getFilename());
2861 for (InputInfoList::const_iterator
2862 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2863 const InputInfo
&II
= *it
;
2864 CmdArgs
.push_back(II
.getFilename());
2868 Args
.MakeArgString(getToolChain().GetProgramPath("gas"));
2869 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2872 void auroraux::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2873 const InputInfo
&Output
,
2874 const InputInfoList
&Inputs
,
2875 const ArgList
&Args
,
2876 const char *LinkingOutput
) const {
2877 ArgStringList CmdArgs
;
2879 if ((!Args
.hasArg(options::OPT_nostdlib
)) &&
2880 (!Args
.hasArg(options::OPT_shared
))) {
2881 CmdArgs
.push_back("-e");
2882 CmdArgs
.push_back("_start");
2885 if (Args
.hasArg(options::OPT_static
)) {
2886 CmdArgs
.push_back("-Bstatic");
2887 CmdArgs
.push_back("-dn");
2889 // CmdArgs.push_back("--eh-frame-hdr");
2890 CmdArgs
.push_back("-Bdynamic");
2891 if (Args
.hasArg(options::OPT_shared
)) {
2892 CmdArgs
.push_back("-shared");
2894 CmdArgs
.push_back("--dynamic-linker");
2895 CmdArgs
.push_back("/lib/ld.so.1"); // 64Bit Path /lib/amd64/ld.so.1
2899 if (Output
.isFilename()) {
2900 CmdArgs
.push_back("-o");
2901 CmdArgs
.push_back(Output
.getFilename());
2903 assert(Output
.isNothing() && "Invalid output.");
2906 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2907 !Args
.hasArg(options::OPT_nostartfiles
)) {
2908 if (!Args
.hasArg(options::OPT_shared
)) {
2909 CmdArgs
.push_back(Args
.MakeArgString(
2910 getToolChain().GetFilePath("crt1.o")));
2911 CmdArgs
.push_back(Args
.MakeArgString(
2912 getToolChain().GetFilePath("crti.o")));
2913 CmdArgs
.push_back(Args
.MakeArgString(
2914 getToolChain().GetFilePath("crtbegin.o")));
2916 CmdArgs
.push_back(Args
.MakeArgString(
2917 getToolChain().GetFilePath("crti.o")));
2919 CmdArgs
.push_back(Args
.MakeArgString(
2920 getToolChain().GetFilePath("crtn.o")));
2923 CmdArgs
.push_back(Args
.MakeArgString("-L/opt/gcc4/lib/gcc/"
2924 + getToolChain().getTripleString()
2927 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
2928 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
2929 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
2931 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
2933 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2934 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
2935 // FIXME: For some reason GCC passes -lgcc before adding
2936 // the default system libraries. Just mimic this for now.
2937 CmdArgs
.push_back("-lgcc");
2939 if (Args
.hasArg(options::OPT_pthread
))
2940 CmdArgs
.push_back("-pthread");
2941 if (!Args
.hasArg(options::OPT_shared
))
2942 CmdArgs
.push_back("-lc");
2943 CmdArgs
.push_back("-lgcc");
2946 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2947 !Args
.hasArg(options::OPT_nostartfiles
)) {
2948 if (!Args
.hasArg(options::OPT_shared
))
2949 CmdArgs
.push_back(Args
.MakeArgString(
2950 getToolChain().GetFilePath("crtend.o")));
2954 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
2955 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2958 void openbsd::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 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2966 options::OPT_Xassembler
);
2968 CmdArgs
.push_back("-o");
2969 CmdArgs
.push_back(Output
.getFilename());
2971 for (InputInfoList::const_iterator
2972 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2973 const InputInfo
&II
= *it
;
2974 CmdArgs
.push_back(II
.getFilename());
2978 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
2979 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2982 void openbsd::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2983 const InputInfo
&Output
,
2984 const InputInfoList
&Inputs
,
2985 const ArgList
&Args
,
2986 const char *LinkingOutput
) const {
2987 const Driver
&D
= getToolChain().getDriver();
2988 ArgStringList CmdArgs
;
2990 if ((!Args
.hasArg(options::OPT_nostdlib
)) &&
2991 (!Args
.hasArg(options::OPT_shared
))) {
2992 CmdArgs
.push_back("-e");
2993 CmdArgs
.push_back("__start");
2996 if (Args
.hasArg(options::OPT_static
)) {
2997 CmdArgs
.push_back("-Bstatic");
2999 if (Args
.hasArg(options::OPT_rdynamic
))
3000 CmdArgs
.push_back("-export-dynamic");
3001 CmdArgs
.push_back("--eh-frame-hdr");
3002 CmdArgs
.push_back("-Bdynamic");
3003 if (Args
.hasArg(options::OPT_shared
)) {
3004 CmdArgs
.push_back("-shared");
3006 CmdArgs
.push_back("-dynamic-linker");
3007 CmdArgs
.push_back("/usr/libexec/ld.so");
3011 if (Output
.isFilename()) {
3012 CmdArgs
.push_back("-o");
3013 CmdArgs
.push_back(Output
.getFilename());
3015 assert(Output
.isNothing() && "Invalid output.");
3018 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3019 !Args
.hasArg(options::OPT_nostartfiles
)) {
3020 if (!Args
.hasArg(options::OPT_shared
)) {
3021 CmdArgs
.push_back(Args
.MakeArgString(
3022 getToolChain().GetFilePath("crt0.o")));
3023 CmdArgs
.push_back(Args
.MakeArgString(
3024 getToolChain().GetFilePath("crtbegin.o")));
3026 CmdArgs
.push_back(Args
.MakeArgString(
3027 getToolChain().GetFilePath("crtbeginS.o")));
3031 std::string Triple
= getToolChain().getTripleString();
3032 if (Triple
.substr(0, 6) == "x86_64")
3033 Triple
.replace(0, 6, "amd64");
3034 CmdArgs
.push_back(Args
.MakeArgString("-L/usr/lib/gcc-lib/" + Triple
+
3037 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3038 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3039 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3041 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3043 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3044 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3046 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3047 CmdArgs
.push_back("-lm");
3050 // FIXME: For some reason GCC passes -lgcc before adding
3051 // the default system libraries. Just mimic this for now.
3052 CmdArgs
.push_back("-lgcc");
3054 if (Args
.hasArg(options::OPT_pthread
))
3055 CmdArgs
.push_back("-pthread");
3056 if (!Args
.hasArg(options::OPT_shared
))
3057 CmdArgs
.push_back("-lc");
3058 CmdArgs
.push_back("-lgcc");
3061 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3062 !Args
.hasArg(options::OPT_nostartfiles
)) {
3063 if (!Args
.hasArg(options::OPT_shared
))
3064 CmdArgs
.push_back(Args
.MakeArgString(
3065 getToolChain().GetFilePath("crtend.o")));
3067 CmdArgs
.push_back(Args
.MakeArgString(
3068 getToolChain().GetFilePath("crtendS.o")));
3072 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3073 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3076 void freebsd::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3077 const InputInfo
&Output
,
3078 const InputInfoList
&Inputs
,
3079 const ArgList
&Args
,
3080 const char *LinkingOutput
) const {
3081 ArgStringList CmdArgs
;
3083 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
3084 // instruct as in the base system to assemble 32-bit code.
3085 if (getToolChain().getArchName() == "i386")
3086 CmdArgs
.push_back("--32");
3089 // Set byte order explicitly
3090 if (getToolChain().getArchName() == "mips")
3091 CmdArgs
.push_back("-EB");
3092 else if (getToolChain().getArchName() == "mipsel")
3093 CmdArgs
.push_back("-EL");
3095 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3096 options::OPT_Xassembler
);
3098 CmdArgs
.push_back("-o");
3099 CmdArgs
.push_back(Output
.getFilename());
3101 for (InputInfoList::const_iterator
3102 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3103 const InputInfo
&II
= *it
;
3104 CmdArgs
.push_back(II
.getFilename());
3108 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3109 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3112 void freebsd::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3113 const InputInfo
&Output
,
3114 const InputInfoList
&Inputs
,
3115 const ArgList
&Args
,
3116 const char *LinkingOutput
) const {
3117 const Driver
&D
= getToolChain().getDriver();
3118 ArgStringList CmdArgs
;
3120 if (Args
.hasArg(options::OPT_static
)) {
3121 CmdArgs
.push_back("-Bstatic");
3123 if (Args
.hasArg(options::OPT_rdynamic
))
3124 CmdArgs
.push_back("-export-dynamic");
3125 CmdArgs
.push_back("--eh-frame-hdr");
3126 if (Args
.hasArg(options::OPT_shared
)) {
3127 CmdArgs
.push_back("-Bshareable");
3129 CmdArgs
.push_back("-dynamic-linker");
3130 CmdArgs
.push_back("/libexec/ld-elf.so.1");
3134 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
3135 // instruct ld in the base system to link 32-bit code.
3136 if (getToolChain().getArchName() == "i386") {
3137 CmdArgs
.push_back("-m");
3138 CmdArgs
.push_back("elf_i386_fbsd");
3141 if (Output
.isFilename()) {
3142 CmdArgs
.push_back("-o");
3143 CmdArgs
.push_back(Output
.getFilename());
3145 assert(Output
.isNothing() && "Invalid output.");
3148 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3149 !Args
.hasArg(options::OPT_nostartfiles
)) {
3150 if (!Args
.hasArg(options::OPT_shared
)) {
3151 CmdArgs
.push_back(Args
.MakeArgString(
3152 getToolChain().GetFilePath("crt1.o")));
3153 CmdArgs
.push_back(Args
.MakeArgString(
3154 getToolChain().GetFilePath("crti.o")));
3155 CmdArgs
.push_back(Args
.MakeArgString(
3156 getToolChain().GetFilePath("crtbegin.o")));
3158 CmdArgs
.push_back(Args
.MakeArgString(
3159 getToolChain().GetFilePath("crti.o")));
3160 CmdArgs
.push_back(Args
.MakeArgString(
3161 getToolChain().GetFilePath("crtbeginS.o")));
3165 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3166 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3167 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3168 Args
.AddAllArgs(CmdArgs
, options::OPT_s
);
3169 Args
.AddAllArgs(CmdArgs
, options::OPT_t
);
3170 Args
.AddAllArgs(CmdArgs
, options::OPT_Z_Flag
);
3171 Args
.AddAllArgs(CmdArgs
, options::OPT_r
);
3173 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3175 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3176 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3178 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3179 CmdArgs
.push_back("-lm");
3181 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
3182 // the default system libraries. Just mimic this for now.
3183 CmdArgs
.push_back("-lgcc");
3184 if (Args
.hasArg(options::OPT_static
)) {
3185 CmdArgs
.push_back("-lgcc_eh");
3187 CmdArgs
.push_back("--as-needed");
3188 CmdArgs
.push_back("-lgcc_s");
3189 CmdArgs
.push_back("--no-as-needed");
3192 if (Args
.hasArg(options::OPT_pthread
))
3193 CmdArgs
.push_back("-lpthread");
3194 CmdArgs
.push_back("-lc");
3196 CmdArgs
.push_back("-lgcc");
3197 if (Args
.hasArg(options::OPT_static
)) {
3198 CmdArgs
.push_back("-lgcc_eh");
3200 CmdArgs
.push_back("--as-needed");
3201 CmdArgs
.push_back("-lgcc_s");
3202 CmdArgs
.push_back("--no-as-needed");
3206 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3207 !Args
.hasArg(options::OPT_nostartfiles
)) {
3208 if (!Args
.hasArg(options::OPT_shared
))
3209 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3212 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3214 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3219 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3220 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3223 void linuxtools::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3224 const InputInfo
&Output
,
3225 const InputInfoList
&Inputs
,
3226 const ArgList
&Args
,
3227 const char *LinkingOutput
) const {
3228 ArgStringList CmdArgs
;
3230 // Add --32/--64 to make sure we get the format we want.
3231 // This is incomplete
3232 if (getToolChain().getArch() == llvm::Triple::x86
) {
3233 CmdArgs
.push_back("--32");
3234 } else if (getToolChain().getArch() == llvm::Triple::x86_64
) {
3235 CmdArgs
.push_back("--64");
3236 } else if (getToolChain().getArch() == llvm::Triple::arm
) {
3237 llvm::StringRef MArch
= getToolChain().getArchName();
3238 if (MArch
== "armv7" || MArch
== "armv7a" || MArch
== "armv7-a")
3239 CmdArgs
.push_back("-mfpu=neon");
3242 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3243 options::OPT_Xassembler
);
3245 CmdArgs
.push_back("-o");
3246 CmdArgs
.push_back(Output
.getFilename());
3248 for (InputInfoList::const_iterator
3249 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3250 const InputInfo
&II
= *it
;
3251 CmdArgs
.push_back(II
.getFilename());
3255 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3256 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3259 void linuxtools::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3260 const InputInfo
&Output
,
3261 const InputInfoList
&Inputs
,
3262 const ArgList
&Args
,
3263 const char *LinkingOutput
) const {
3264 const toolchains::Linux
& ToolChain
=
3265 static_cast<const toolchains::Linux
&>(getToolChain());
3266 const Driver
&D
= ToolChain
.getDriver();
3267 ArgStringList CmdArgs
;
3269 // Silence warning for "clang -g foo.o -o foo"
3270 Args
.ClaimAllArgs(options::OPT_g_Group
);
3271 // and for "clang -g foo.o -o foo". Other warning options are already
3272 // handled somewhere else.
3273 Args
.ClaimAllArgs(options::OPT_w
);
3275 if (Arg
*A
= Args
.getLastArg(options::OPT__sysroot_EQ
)) {
3276 CmdArgs
.push_back("--sysroot");
3277 CmdArgs
.push_back(A
->getValue(Args
));
3280 if (Args
.hasArg(options::OPT_pie
))
3281 CmdArgs
.push_back("-pie");
3283 if (Args
.hasArg(options::OPT_rdynamic
))
3284 CmdArgs
.push_back("-export-dynamic");
3286 if (Args
.hasArg(options::OPT_s
))
3287 CmdArgs
.push_back("-s");
3289 for (std::vector
<std::string
>::const_iterator i
= ToolChain
.ExtraOpts
.begin(),
3290 e
= ToolChain
.ExtraOpts
.end();
3292 CmdArgs
.push_back(i
->c_str());
3294 if (!Args
.hasArg(options::OPT_static
)) {
3295 CmdArgs
.push_back("--eh-frame-hdr");
3298 CmdArgs
.push_back("-m");
3299 if (ToolChain
.getArch() == llvm::Triple::x86
)
3300 CmdArgs
.push_back("elf_i386");
3301 else if (ToolChain
.getArch() == llvm::Triple::arm
)
3302 CmdArgs
.push_back("armelf_linux_eabi");
3304 CmdArgs
.push_back("elf_x86_64");
3306 if (Args
.hasArg(options::OPT_static
)) {
3307 if (ToolChain
.getArch() == llvm::Triple::arm
)
3308 CmdArgs
.push_back("-Bstatic");
3310 CmdArgs
.push_back("-static");
3311 } else if (Args
.hasArg(options::OPT_shared
)) {
3312 CmdArgs
.push_back("-shared");
3315 if (ToolChain
.getArch() == llvm::Triple::arm
||
3316 (!Args
.hasArg(options::OPT_static
) &&
3317 !Args
.hasArg(options::OPT_shared
))) {
3318 CmdArgs
.push_back("-dynamic-linker");
3319 if (ToolChain
.getArch() == llvm::Triple::x86
)
3320 CmdArgs
.push_back("/lib/ld-linux.so.2");
3321 else if (ToolChain
.getArch() == llvm::Triple::arm
)
3322 CmdArgs
.push_back("/lib/ld-linux.so.3");
3324 CmdArgs
.push_back("/lib64/ld-linux-x86-64.so.2");
3327 CmdArgs
.push_back("-o");
3328 CmdArgs
.push_back(Output
.getFilename());
3330 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3331 !Args
.hasArg(options::OPT_nostartfiles
)) {
3332 const char *crt1
= NULL
;
3333 if (!Args
.hasArg(options::OPT_shared
)){
3334 if (Args
.hasArg(options::OPT_pie
))
3340 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath(crt1
)));
3342 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath("crti.o")));
3344 const char *crtbegin
;
3345 if (Args
.hasArg(options::OPT_static
))
3346 crtbegin
= "crtbeginT.o";
3347 else if (Args
.hasArg(options::OPT_shared
) || Args
.hasArg(options::OPT_pie
))
3348 crtbegin
= "crtbeginS.o";
3350 crtbegin
= "crtbegin.o";
3351 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath(crtbegin
)));
3354 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3356 const ToolChain::path_list Paths
= ToolChain
.getFilePaths();
3358 for (ToolChain::path_list::const_iterator i
= Paths
.begin(),
3361 const std::string
&s
= *i
;
3362 CmdArgs
.push_back(Args
.MakeArgString(std::string("-L") + s
));
3365 AddLinkerInputs(ToolChain
, Inputs
, Args
, CmdArgs
);
3367 if (D
.CCCIsCXX
&& !Args
.hasArg(options::OPT_nostdlib
)) {
3368 ToolChain
.AddCXXStdlibLibArgs(Args
, CmdArgs
);
3369 CmdArgs
.push_back("-lm");
3372 if (Args
.hasArg(options::OPT_static
))
3373 CmdArgs
.push_back("--start-group");
3375 if (!Args
.hasArg(options::OPT_nostdlib
)) {
3377 CmdArgs
.push_back("-lgcc");
3379 if (Args
.hasArg(options::OPT_static
)) {
3381 CmdArgs
.push_back("-lgcc");
3384 CmdArgs
.push_back("--as-needed");
3385 CmdArgs
.push_back("-lgcc_s");
3387 CmdArgs
.push_back("--no-as-needed");
3390 if (Args
.hasArg(options::OPT_static
))
3391 CmdArgs
.push_back("-lgcc_eh");
3392 else if (!Args
.hasArg(options::OPT_shared
) && D
.CCCIsCXX
)
3393 CmdArgs
.push_back("-lgcc");
3395 if (Args
.hasArg(options::OPT_pthread
) ||
3396 Args
.hasArg(options::OPT_pthreads
))
3397 CmdArgs
.push_back("-lpthread");
3399 CmdArgs
.push_back("-lc");
3401 if (Args
.hasArg(options::OPT_static
))
3402 CmdArgs
.push_back("--end-group");
3405 CmdArgs
.push_back("-lgcc");
3408 CmdArgs
.push_back("--as-needed");
3409 CmdArgs
.push_back("-lgcc_s");
3411 CmdArgs
.push_back("--no-as-needed");
3413 if (!Args
.hasArg(options::OPT_shared
) && D
.CCCIsCXX
)
3414 CmdArgs
.push_back("-lgcc");
3418 if (!Args
.hasArg(options::OPT_nostartfiles
)) {
3420 if (Args
.hasArg(options::OPT_shared
) || Args
.hasArg(options::OPT_pie
))
3421 crtend
= "crtendS.o";
3423 crtend
= "crtend.o";
3425 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath(crtend
)));
3426 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath("crtn.o")));
3430 if (Args
.hasArg(options::OPT_use_gold_plugin
)) {
3431 CmdArgs
.push_back("-plugin");
3432 std::string Plugin
= ToolChain
.getDriver().Dir
+ "/../lib/LLVMgold.so";
3433 CmdArgs
.push_back(Args
.MakeArgString(Plugin
));
3436 C
.addCommand(new Command(JA
, *this, ToolChain
.Linker
.c_str(), CmdArgs
));
3439 void minix::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3440 const InputInfo
&Output
,
3441 const InputInfoList
&Inputs
,
3442 const ArgList
&Args
,
3443 const char *LinkingOutput
) const {
3444 ArgStringList CmdArgs
;
3446 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3447 options::OPT_Xassembler
);
3449 CmdArgs
.push_back("-o");
3450 CmdArgs
.push_back(Output
.getFilename());
3452 for (InputInfoList::const_iterator
3453 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3454 const InputInfo
&II
= *it
;
3455 CmdArgs
.push_back(II
.getFilename());
3459 Args
.MakeArgString(getToolChain().GetProgramPath("gas"));
3460 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3463 void minix::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3464 const InputInfo
&Output
,
3465 const InputInfoList
&Inputs
,
3466 const ArgList
&Args
,
3467 const char *LinkingOutput
) const {
3468 const Driver
&D
= getToolChain().getDriver();
3469 ArgStringList CmdArgs
;
3471 if (Output
.isFilename()) {
3472 CmdArgs
.push_back("-o");
3473 CmdArgs
.push_back(Output
.getFilename());
3475 assert(Output
.isNothing() && "Invalid output.");
3478 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3479 !Args
.hasArg(options::OPT_nostartfiles
))
3480 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3481 "/usr/gnu/lib/crtso.o")));
3483 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3484 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3485 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3487 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3489 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3490 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3492 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3493 CmdArgs
.push_back("-lm");
3496 if (Args
.hasArg(options::OPT_pthread
))
3497 CmdArgs
.push_back("-lpthread");
3498 CmdArgs
.push_back("-lc");
3499 CmdArgs
.push_back("-lgcc");
3500 CmdArgs
.push_back("-L/usr/gnu/lib");
3501 // FIXME: fill in the correct search path for the final
3502 // support libraries.
3503 CmdArgs
.push_back("-L/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
3506 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3507 !Args
.hasArg(options::OPT_nostartfiles
)) {
3508 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3509 "/usr/gnu/lib/libend.a")));
3513 Args
.MakeArgString(getToolChain().GetProgramPath("/usr/gnu/bin/gld"));
3514 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3519 // For now, DragonFly Assemble does just about the same as for
3520 // FreeBSD, but this may change soon.
3521 void dragonfly::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3522 const InputInfo
&Output
,
3523 const InputInfoList
&Inputs
,
3524 const ArgList
&Args
,
3525 const char *LinkingOutput
) const {
3526 ArgStringList CmdArgs
;
3528 // When building 32-bit code on DragonFly/pc64, we have to explicitly
3529 // instruct as in the base system to assemble 32-bit code.
3530 if (getToolChain().getArchName() == "i386")
3531 CmdArgs
.push_back("--32");
3533 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3534 options::OPT_Xassembler
);
3536 CmdArgs
.push_back("-o");
3537 CmdArgs
.push_back(Output
.getFilename());
3539 for (InputInfoList::const_iterator
3540 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3541 const InputInfo
&II
= *it
;
3542 CmdArgs
.push_back(II
.getFilename());
3546 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3547 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3550 void dragonfly::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3551 const InputInfo
&Output
,
3552 const InputInfoList
&Inputs
,
3553 const ArgList
&Args
,
3554 const char *LinkingOutput
) const {
3555 const Driver
&D
= getToolChain().getDriver();
3556 ArgStringList CmdArgs
;
3558 if (Args
.hasArg(options::OPT_static
)) {
3559 CmdArgs
.push_back("-Bstatic");
3561 if (Args
.hasArg(options::OPT_shared
))
3562 CmdArgs
.push_back("-Bshareable");
3564 CmdArgs
.push_back("-dynamic-linker");
3565 CmdArgs
.push_back("/usr/libexec/ld-elf.so.2");
3569 // When building 32-bit code on DragonFly/pc64, we have to explicitly
3570 // instruct ld in the base system to link 32-bit code.
3571 if (getToolChain().getArchName() == "i386") {
3572 CmdArgs
.push_back("-m");
3573 CmdArgs
.push_back("elf_i386");
3576 if (Output
.isFilename()) {
3577 CmdArgs
.push_back("-o");
3578 CmdArgs
.push_back(Output
.getFilename());
3580 assert(Output
.isNothing() && "Invalid output.");
3583 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3584 !Args
.hasArg(options::OPT_nostartfiles
)) {
3585 if (!Args
.hasArg(options::OPT_shared
)) {
3587 Args
.MakeArgString(getToolChain().GetFilePath("crt1.o")));
3589 Args
.MakeArgString(getToolChain().GetFilePath("crti.o")));
3591 Args
.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
3594 Args
.MakeArgString(getToolChain().GetFilePath("crti.o")));
3596 Args
.MakeArgString(getToolChain().GetFilePath("crtbeginS.o")));
3600 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3601 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3602 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3604 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3606 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3607 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3608 // FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of
3610 CmdArgs
.push_back("-L/usr/lib/gcc41");
3612 if (!Args
.hasArg(options::OPT_static
)) {
3613 CmdArgs
.push_back("-rpath");
3614 CmdArgs
.push_back("/usr/lib/gcc41");
3616 CmdArgs
.push_back("-rpath-link");
3617 CmdArgs
.push_back("/usr/lib/gcc41");
3619 CmdArgs
.push_back("-rpath");
3620 CmdArgs
.push_back("/usr/lib");
3622 CmdArgs
.push_back("-rpath-link");
3623 CmdArgs
.push_back("/usr/lib");
3627 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3628 CmdArgs
.push_back("-lm");
3631 if (Args
.hasArg(options::OPT_shared
)) {
3632 CmdArgs
.push_back("-lgcc_pic");
3634 CmdArgs
.push_back("-lgcc");
3638 if (Args
.hasArg(options::OPT_pthread
))
3639 CmdArgs
.push_back("-lpthread");
3641 if (!Args
.hasArg(options::OPT_nolibc
)) {
3642 CmdArgs
.push_back("-lc");
3645 if (Args
.hasArg(options::OPT_shared
)) {
3646 CmdArgs
.push_back("-lgcc_pic");
3648 CmdArgs
.push_back("-lgcc");
3652 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3653 !Args
.hasArg(options::OPT_nostartfiles
)) {
3654 if (!Args
.hasArg(options::OPT_shared
))
3655 CmdArgs
.push_back(Args
.MakeArgString(
3656 getToolChain().GetFilePath("crtend.o")));
3658 CmdArgs
.push_back(Args
.MakeArgString(
3659 getToolChain().GetFilePath("crtendS.o")));
3660 CmdArgs
.push_back(Args
.MakeArgString(
3661 getToolChain().GetFilePath("crtn.o")));
3665 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3666 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3669 void visualstudio::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3670 const InputInfo
&Output
,
3671 const InputInfoList
&Inputs
,
3672 const ArgList
&Args
,
3673 const char *LinkingOutput
) const {
3674 ArgStringList CmdArgs
;
3676 if (Output
.isFilename()) {
3677 CmdArgs
.push_back(Args
.MakeArgString(std::string("-out:") +
3678 Output
.getFilename()));
3680 assert(Output
.isNothing() && "Invalid output.");
3683 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3684 !Args
.hasArg(options::OPT_nostartfiles
)) {
3685 CmdArgs
.push_back("-defaultlib:libcmt");
3688 CmdArgs
.push_back("-nologo");
3690 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3693 Args
.MakeArgString(getToolChain().GetProgramPath("link.exe"));
3694 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));