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 switch(Triple
.getEnvironment()) {
432 case llvm::Triple::GNUEABI
:
433 ABIName
= "aapcs-linux";
435 case llvm::Triple::EABI
:
439 ABIName
= "apcs-gnu";
442 CmdArgs
.push_back("-target-abi");
443 CmdArgs
.push_back(ABIName
);
445 // Set the CPU based on -march= and -mcpu=.
446 CmdArgs
.push_back("-target-cpu");
447 CmdArgs
.push_back(getARMTargetCPU(Args
, Triple
));
449 // Select the float ABI as determined by -msoft-float, -mhard-float, and
451 llvm::StringRef FloatABI
;
452 if (Arg
*A
= Args
.getLastArg(options::OPT_msoft_float
,
453 options::OPT_mhard_float
,
454 options::OPT_mfloat_abi_EQ
)) {
455 if (A
->getOption().matches(options::OPT_msoft_float
))
457 else if (A
->getOption().matches(options::OPT_mhard_float
))
460 FloatABI
= A
->getValue(Args
);
461 if (FloatABI
!= "soft" && FloatABI
!= "softfp" && FloatABI
!= "hard") {
462 D
.Diag(clang::diag::err_drv_invalid_mfloat_abi
)
463 << A
->getAsString(Args
);
469 // If unspecified, choose the default based on the platform.
470 if (FloatABI
.empty()) {
471 const llvm::Triple
&Triple
= getToolChain().getTriple();
472 switch (Triple
.getOS()) {
473 case llvm::Triple::Darwin
: {
474 // Darwin defaults to "softfp" for v6 and v7.
476 // FIXME: Factor out an ARM class so we can cache the arch somewhere.
477 llvm::StringRef ArchName
=
478 getLLVMArchSuffixForARM(getARMTargetCPU(Args
, Triple
));
479 if (ArchName
.startswith("v6") || ArchName
.startswith("v7"))
486 case llvm::Triple::Linux
: {
487 if (getToolChain().getTriple().getEnvironment() == llvm::Triple::GNUEABI
) {
495 switch(Triple
.getEnvironment()) {
496 case llvm::Triple::GNUEABI
:
499 case llvm::Triple::EABI
:
500 // EABI is always AAPCS, and if it was not marked 'hard', it's softfp
504 // Assume "soft", but warn the user we are guessing.
506 D
.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is
) << "soft";
512 if (FloatABI
== "soft") {
513 // Floating point operations and argument passing are soft.
515 // FIXME: This changes CPP defines, we need -target-soft-float.
516 CmdArgs
.push_back("-msoft-float");
517 CmdArgs
.push_back("-mfloat-abi");
518 CmdArgs
.push_back("soft");
519 } else if (FloatABI
== "softfp") {
520 // Floating point operations are hard, but argument passing is soft.
521 CmdArgs
.push_back("-mfloat-abi");
522 CmdArgs
.push_back("soft");
524 // Floating point operations and argument passing are hard.
525 assert(FloatABI
== "hard" && "Invalid float abi!");
526 CmdArgs
.push_back("-mfloat-abi");
527 CmdArgs
.push_back("hard");
530 // Set appropriate target features for floating point mode.
532 // FIXME: Note, this is a hack, the LLVM backend doesn't actually use these
533 // yet (it uses the -mfloat-abi and -msoft-float options above), and it is
534 // stripped out by the ARM target.
536 // Use software floating point operations?
537 if (FloatABI
== "soft") {
538 CmdArgs
.push_back("-target-feature");
539 CmdArgs
.push_back("+soft-float");
542 // Use software floating point argument passing?
543 if (FloatABI
!= "hard") {
544 CmdArgs
.push_back("-target-feature");
545 CmdArgs
.push_back("+soft-float-abi");
550 // FIXME: Centralize feature selection, defaulting shouldn't be also in the
552 if (const Arg
*A
= Args
.getLastArg(options::OPT_mfpu_EQ
)) {
553 llvm::StringRef FPU
= A
->getValue(Args
);
555 // Set the target features based on the FPU.
556 if (FPU
== "fpa" || FPU
== "fpe2" || FPU
== "fpe3" || FPU
== "maverick") {
557 // Disable any default FPU support.
558 CmdArgs
.push_back("-target-feature");
559 CmdArgs
.push_back("-vfp2");
560 CmdArgs
.push_back("-target-feature");
561 CmdArgs
.push_back("-vfp3");
562 CmdArgs
.push_back("-target-feature");
563 CmdArgs
.push_back("-neon");
564 } else if (FPU
== "vfp") {
565 CmdArgs
.push_back("-target-feature");
566 CmdArgs
.push_back("+vfp2");
567 } else if (FPU
== "vfp3") {
568 CmdArgs
.push_back("-target-feature");
569 CmdArgs
.push_back("+vfp3");
570 } else if (FPU
== "neon") {
571 CmdArgs
.push_back("-target-feature");
572 CmdArgs
.push_back("+neon");
574 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
578 void Clang::AddMIPSTargetArgs(const ArgList
&Args
,
579 ArgStringList
&CmdArgs
) const {
580 const Driver
&D
= getToolChain().getDriver();
582 // Select the ABI to use.
583 const char *ABIName
= 0;
584 if (Arg
*A
= Args
.getLastArg(options::OPT_mabi_EQ
)) {
585 ABIName
= A
->getValue(Args
);
590 CmdArgs
.push_back("-target-abi");
591 CmdArgs
.push_back(ABIName
);
593 if (const Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
594 llvm::StringRef MArch
= A
->getValue(Args
);
595 CmdArgs
.push_back("-target-cpu");
597 if ((MArch
== "r2000") || (MArch
== "r3000"))
598 CmdArgs
.push_back("mips1");
599 else if (MArch
== "r6000")
600 CmdArgs
.push_back("mips2");
602 CmdArgs
.push_back(MArch
.str().c_str());
605 // Select the float ABI as determined by -msoft-float, -mhard-float, and
606 llvm::StringRef FloatABI
;
607 if (Arg
*A
= Args
.getLastArg(options::OPT_msoft_float
,
608 options::OPT_mhard_float
)) {
609 if (A
->getOption().matches(options::OPT_msoft_float
))
611 else if (A
->getOption().matches(options::OPT_mhard_float
))
615 // If unspecified, choose the default based on the platform.
616 if (FloatABI
.empty()) {
617 // Assume "soft", but warn the user we are guessing.
619 D
.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is
) << "soft";
622 if (FloatABI
== "soft") {
623 // Floating point operations and argument passing are soft.
625 // FIXME: This changes CPP defines, we need -target-soft-float.
626 CmdArgs
.push_back("-msoft-float");
628 assert(FloatABI
== "hard" && "Invalid float abi!");
629 CmdArgs
.push_back("-mhard-float");
633 void Clang::AddSparcTargetArgs(const ArgList
&Args
,
634 ArgStringList
&CmdArgs
) const {
635 const Driver
&D
= getToolChain().getDriver();
637 if (const Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
638 llvm::StringRef MArch
= A
->getValue(Args
);
639 CmdArgs
.push_back("-target-cpu");
640 CmdArgs
.push_back(MArch
.str().c_str());
643 // Select the float ABI as determined by -msoft-float, -mhard-float, and
644 llvm::StringRef FloatABI
;
645 if (Arg
*A
= Args
.getLastArg(options::OPT_msoft_float
,
646 options::OPT_mhard_float
)) {
647 if (A
->getOption().matches(options::OPT_msoft_float
))
649 else if (A
->getOption().matches(options::OPT_mhard_float
))
653 // If unspecified, choose the default based on the platform.
654 if (FloatABI
.empty()) {
655 switch (getToolChain().getTriple().getOS()) {
657 // Assume "soft", but warn the user we are guessing.
659 D
.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is
) << "soft";
664 if (FloatABI
== "soft") {
665 // Floating point operations and argument passing are soft.
667 // FIXME: This changes CPP defines, we need -target-soft-float.
668 CmdArgs
.push_back("-msoft-float");
669 CmdArgs
.push_back("soft");
670 CmdArgs
.push_back("-target-feature");
671 CmdArgs
.push_back("+soft-float");
673 assert(FloatABI
== "hard" && "Invalid float abi!");
674 CmdArgs
.push_back("-mhard-float");
678 void Clang::AddX86TargetArgs(const ArgList
&Args
,
679 ArgStringList
&CmdArgs
) const {
680 if (!Args
.hasFlag(options::OPT_mred_zone
,
681 options::OPT_mno_red_zone
,
683 Args
.hasArg(options::OPT_mkernel
) ||
684 Args
.hasArg(options::OPT_fapple_kext
))
685 CmdArgs
.push_back("-disable-red-zone");
687 if (Args
.hasFlag(options::OPT_msoft_float
,
688 options::OPT_mno_soft_float
,
690 CmdArgs
.push_back("-no-implicit-float");
692 const char *CPUName
= 0;
693 if (const Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
694 if (llvm::StringRef(A
->getValue(Args
)) == "native") {
695 // FIXME: Reject attempts to use -march=native unless the target matches
698 // FIXME: We should also incorporate the detected target features for use
700 std::string CPU
= llvm::sys::getHostCPUName();
702 CPUName
= Args
.MakeArgString(CPU
);
704 CPUName
= A
->getValue(Args
);
707 // Select the default CPU if none was given (or detection failed).
709 // FIXME: Need target hooks.
710 if (getToolChain().getOS().startswith("darwin")) {
711 if (getToolChain().getArchName() == "x86_64")
713 else if (getToolChain().getArchName() == "i386")
715 } else if (getToolChain().getOS().startswith("haiku")) {
716 if (getToolChain().getArchName() == "x86_64")
718 else if (getToolChain().getArchName() == "i386")
720 } else if (getToolChain().getOS().startswith("openbsd")) {
721 if (getToolChain().getArchName() == "x86_64")
723 else if (getToolChain().getArchName() == "i386")
725 } else if (getToolChain().getOS().startswith("netbsd")) {
726 if (getToolChain().getArchName() == "x86_64")
728 else if (getToolChain().getArchName() == "i386")
731 if (getToolChain().getArchName() == "x86_64")
733 else if (getToolChain().getArchName() == "i386")
734 CPUName
= "pentium4";
739 CmdArgs
.push_back("-target-cpu");
740 CmdArgs
.push_back(CPUName
);
743 for (arg_iterator it
= Args
.filtered_begin(options::OPT_m_x86_Features_Group
),
744 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
745 llvm::StringRef Name
= (*it
)->getOption().getName();
749 assert(Name
.startswith("-m") && "Invalid feature name.");
750 Name
= Name
.substr(2);
752 bool IsNegative
= Name
.startswith("no-");
754 Name
= Name
.substr(3);
756 CmdArgs
.push_back("-target-feature");
757 CmdArgs
.push_back(Args
.MakeArgString((IsNegative
? "-" : "+") + Name
));
761 static bool needsExceptions(const ArgList
&Args
, types::ID InputType
,
762 const llvm::Triple
&Triple
) {
763 // Handle -fno-exceptions.
764 if (Arg
*A
= Args
.getLastArg(options::OPT_fexceptions
,
765 options::OPT_fno_exceptions
)) {
766 if (A
->getOption().matches(options::OPT_fexceptions
))
772 // Otherwise, C++ inputs use exceptions.
773 if (types::isCXX(InputType
))
776 // As do Objective-C non-fragile ABI inputs and all Objective-C inputs on
777 // x86_64 and ARM after SnowLeopard.
778 if (types::isObjC(InputType
)) {
779 if (Args
.hasArg(options::OPT_fobjc_nonfragile_abi
))
781 if (Triple
.getOS() != llvm::Triple::Darwin
)
783 return (Triple
.getDarwinMajorNumber() >= 9 &&
784 (Triple
.getArch() == llvm::Triple::x86_64
||
785 Triple
.getArch() == llvm::Triple::arm
));
791 void Clang::ConstructJob(Compilation
&C
, const JobAction
&JA
,
792 const InputInfo
&Output
,
793 const InputInfoList
&Inputs
,
795 const char *LinkingOutput
) const {
796 bool KernelOrKext
= Args
.hasArg(options::OPT_mkernel
,
797 options::OPT_fapple_kext
);
798 const Driver
&D
= getToolChain().getDriver();
799 ArgStringList CmdArgs
;
801 assert(Inputs
.size() == 1 && "Unable to handle multiple inputs.");
803 // Invoke ourselves in -cc1 mode.
805 // FIXME: Implement custom jobs for internal actions.
806 CmdArgs
.push_back("-cc1");
808 // Add the "effective" target triple.
809 CmdArgs
.push_back("-triple");
810 std::string TripleStr
= getToolChain().ComputeEffectiveClangTriple(Args
);
811 CmdArgs
.push_back(Args
.MakeArgString(TripleStr
));
813 // Select the appropriate action.
814 bool IsRewriter
= false;
815 if (isa
<AnalyzeJobAction
>(JA
)) {
816 assert(JA
.getType() == types::TY_Plist
&& "Invalid output type.");
817 CmdArgs
.push_back("-analyze");
818 } else if (isa
<PreprocessJobAction
>(JA
)) {
819 if (Output
.getType() == types::TY_Dependencies
)
820 CmdArgs
.push_back("-Eonly");
822 CmdArgs
.push_back("-E");
823 } else if (isa
<AssembleJobAction
>(JA
)) {
824 CmdArgs
.push_back("-emit-obj");
826 // At -O0, we use -mrelax-all by default.
828 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
))
829 IsOpt
= !A
->getOption().matches(options::OPT_O0
);
830 if (Args
.hasFlag(options::OPT_mrelax_all
,
831 options::OPT_mno_relax_all
,
833 CmdArgs
.push_back("-mrelax-all");
835 // When using an integrated assembler, translate -Wa, and -Xassembler
837 for (arg_iterator it
= Args
.filtered_begin(options::OPT_Wa_COMMA
,
838 options::OPT_Xassembler
),
839 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
843 for (unsigned i
= 0, e
= A
->getNumValues(); i
!= e
; ++i
) {
844 llvm::StringRef Value
= A
->getValue(Args
, i
);
846 if (Value
== "-force_cpusubtype_ALL") {
847 // Do nothing, this is the default and we don't support anything else.
848 } else if (Value
== "-L") {
849 // We don't support -L yet, but it isn't important enough to error
850 // on. No one should really be using it for a semantic change.
851 D
.Diag(clang::diag::warn_drv_unsupported_option_argument
)
852 << A
->getOption().getName() << Value
;
854 D
.Diag(clang::diag::err_drv_unsupported_option_argument
)
855 << A
->getOption().getName() << Value
;
860 // Also ignore explicit -force_cpusubtype_ALL option.
861 (void) Args
.hasArg(options::OPT_force__cpusubtype__ALL
);
862 } else if (isa
<PrecompileJobAction
>(JA
)) {
863 // Use PCH if the user requested it.
864 bool UsePCH
= D
.CCCUsePCH
;
867 CmdArgs
.push_back("-emit-pch");
869 CmdArgs
.push_back("-emit-pth");
871 assert(isa
<CompileJobAction
>(JA
) && "Invalid action for clang tool.");
873 if (JA
.getType() == types::TY_Nothing
) {
874 CmdArgs
.push_back("-fsyntax-only");
875 } else if (JA
.getType() == types::TY_LLVM_IR
||
876 JA
.getType() == types::TY_LTO_IR
) {
877 CmdArgs
.push_back("-emit-llvm");
878 } else if (JA
.getType() == types::TY_LLVM_BC
||
879 JA
.getType() == types::TY_LTO_BC
) {
880 CmdArgs
.push_back("-emit-llvm-bc");
881 } else if (JA
.getType() == types::TY_PP_Asm
) {
882 CmdArgs
.push_back("-S");
883 } else if (JA
.getType() == types::TY_AST
) {
884 CmdArgs
.push_back("-emit-pch");
885 } else if (JA
.getType() == types::TY_RewrittenObjC
) {
886 CmdArgs
.push_back("-rewrite-objc");
889 assert(JA
.getType() == types::TY_PP_Asm
&&
890 "Unexpected output type!");
894 // The make clang go fast button.
895 CmdArgs
.push_back("-disable-free");
897 // Disable the verification pass in -asserts builds.
899 CmdArgs
.push_back("-disable-llvm-verifier");
902 // Set the main file name, so that debug info works even with
904 CmdArgs
.push_back("-main-file-name");
905 CmdArgs
.push_back(darwin::CC1::getBaseInputName(Args
, Inputs
));
907 // Some flags which affect the language (via preprocessor
908 // defines). See darwin::CC1::AddCPPArgs.
909 if (Args
.hasArg(options::OPT_static
))
910 CmdArgs
.push_back("-static-define");
912 if (isa
<AnalyzeJobAction
>(JA
)) {
913 // Enable region store model by default.
914 CmdArgs
.push_back("-analyzer-store=region");
916 // Treat blocks as analysis entry points.
917 CmdArgs
.push_back("-analyzer-opt-analyze-nested-blocks");
919 // Add default argument set.
920 if (!Args
.hasArg(options::OPT__analyzer_no_default_checks
)) {
921 types::ID InputType
= Inputs
[0].getType();
923 // Checks to perform for all language types.
924 CmdArgs
.push_back("-analyzer-check-dead-stores");
926 // Checks to perform for Objective-C/Objective-C++.
927 if (types::isObjC(InputType
)) {
928 CmdArgs
.push_back("-analyzer-check-objc-methodsigs");
929 CmdArgs
.push_back("-analyzer-check-objc-unused-ivars");
930 CmdArgs
.push_back("-analyzer-check-objc-self-init");
931 // Do not enable the missing -dealloc check.
932 // '-analyzer-check-objc-missing-dealloc',
935 // Checks to perform for all languages *except* C++.
936 if (!types::isCXX(InputType
)) {
937 // Do not enable the security-syntatic check since it
938 // it needs to be refined (known issues).
939 // CmdArgs.push_back("-analyzer-check-security-syntactic");
941 // NOTE: Leaving -analyzer-check-objc-mem here is intentional.
942 // It also checks C code.
943 CmdArgs
.push_back("-analyzer-check-objc-mem");
945 CmdArgs
.push_back("-analyzer-eagerly-assume");
946 CmdArgs
.push_back("-analyzer-check-idempotent-operations");
950 // Set the output format. The default is plist, for (lame) historical
952 CmdArgs
.push_back("-analyzer-output");
953 if (Arg
*A
= Args
.getLastArg(options::OPT__analyzer_output
))
954 CmdArgs
.push_back(A
->getValue(Args
));
956 CmdArgs
.push_back("plist");
958 // Disable the presentation of standard compiler warnings when
959 // using --analyze. We only want to show static analyzer diagnostics
960 // or frontend errors.
961 CmdArgs
.push_back("-w");
963 // Add -Xanalyzer arguments when running as analyzer.
964 Args
.AddAllArgValues(CmdArgs
, options::OPT_Xanalyzer
);
967 CheckCodeGenerationOptions(D
, Args
);
969 // Perform argument translation for LLVM backend. This
970 // takes some care in reconciling with llvm-gcc. The
971 // issue is that llvm-gcc translates these options based on
972 // the values in cc1, whereas we are processing based on
973 // the driver arguments.
975 // This comes from the default translation the driver + cc1
976 // would do to enable flag_pic.
978 // FIXME: Centralize this code.
979 bool PICEnabled
= (Args
.hasArg(options::OPT_fPIC
) ||
980 Args
.hasArg(options::OPT_fpic
) ||
981 Args
.hasArg(options::OPT_fPIE
) ||
982 Args
.hasArg(options::OPT_fpie
));
983 bool PICDisabled
= (Args
.hasArg(options::OPT_mkernel
) ||
984 Args
.hasArg(options::OPT_static
));
985 const char *Model
= getToolChain().GetForcedPicModel();
987 if (Args
.hasArg(options::OPT_mdynamic_no_pic
))
988 Model
= "dynamic-no-pic";
989 else if (PICDisabled
)
994 Model
= getToolChain().GetDefaultRelocationModel();
996 if (llvm::StringRef(Model
) != "pic") {
997 CmdArgs
.push_back("-mrelocation-model");
998 CmdArgs
.push_back(Model
);
1001 // Infer the __PIC__ value.
1003 // FIXME: This isn't quite right on Darwin, which always sets
1005 if (strcmp(Model
, "pic") == 0 || strcmp(Model
, "dynamic-no-pic") == 0) {
1006 CmdArgs
.push_back("-pic-level");
1007 CmdArgs
.push_back(Args
.hasArg(options::OPT_fPIC
) ? "2" : "1");
1009 if (!Args
.hasFlag(options::OPT_fmerge_all_constants
,
1010 options::OPT_fno_merge_all_constants
))
1011 CmdArgs
.push_back("-no-merge-all-constants");
1013 // LLVM Code Generator Options.
1015 // FIXME: Set --enable-unsafe-fp-math.
1016 if (Args
.hasFlag(options::OPT_fno_omit_frame_pointer
,
1017 options::OPT_fomit_frame_pointer
))
1018 CmdArgs
.push_back("-mdisable-fp-elim");
1019 if (!Args
.hasFlag(options::OPT_fzero_initialized_in_bss
,
1020 options::OPT_fno_zero_initialized_in_bss
))
1021 CmdArgs
.push_back("-mno-zero-initialized-in-bss");
1022 if (!Args
.hasFlag(options::OPT_fstrict_aliasing
,
1023 options::OPT_fno_strict_aliasing
,
1024 getToolChain().IsStrictAliasingDefault()))
1025 CmdArgs
.push_back("-relaxed-aliasing");
1027 // Decide whether to use verbose asm. Verbose assembly is the default on
1028 // toolchains which have the integrated assembler on by default.
1029 bool IsVerboseAsmDefault
= getToolChain().IsIntegratedAssemblerDefault();
1030 if (Args
.hasFlag(options::OPT_fverbose_asm
, options::OPT_fno_verbose_asm
,
1031 IsVerboseAsmDefault
) ||
1032 Args
.hasArg(options::OPT_dA
))
1033 CmdArgs
.push_back("-masm-verbose");
1035 if (Args
.hasArg(options::OPT_fdebug_pass_structure
)) {
1036 CmdArgs
.push_back("-mdebug-pass");
1037 CmdArgs
.push_back("Structure");
1039 if (Args
.hasArg(options::OPT_fdebug_pass_arguments
)) {
1040 CmdArgs
.push_back("-mdebug-pass");
1041 CmdArgs
.push_back("Arguments");
1044 // Enable -mconstructor-aliases except on darwin, where we have to
1045 // work around a linker bug; see <rdar://problem/7651567>.
1046 if (getToolChain().getTriple().getOS() != llvm::Triple::Darwin
)
1047 CmdArgs
.push_back("-mconstructor-aliases");
1049 if (Args
.hasArg(options::OPT_mms_bitfields
)) {
1050 CmdArgs
.push_back("-mms-bitfields");
1053 // This is a coarse approximation of what llvm-gcc actually does, both
1054 // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
1055 // complicated ways.
1056 bool AsynchronousUnwindTables
=
1057 Args
.hasFlag(options::OPT_fasynchronous_unwind_tables
,
1058 options::OPT_fno_asynchronous_unwind_tables
,
1059 getToolChain().IsUnwindTablesDefault() &&
1061 if (Args
.hasFlag(options::OPT_funwind_tables
, options::OPT_fno_unwind_tables
,
1062 AsynchronousUnwindTables
))
1063 CmdArgs
.push_back("-munwind-tables");
1065 if (Arg
*A
= Args
.getLastArg(options::OPT_flimited_precision_EQ
)) {
1066 CmdArgs
.push_back("-mlimit-float-precision");
1067 CmdArgs
.push_back(A
->getValue(Args
));
1070 // FIXME: Handle -mtune=.
1071 (void) Args
.hasArg(options::OPT_mtune_EQ
);
1073 if (Arg
*A
= Args
.getLastArg(options::OPT_mcmodel_EQ
)) {
1074 CmdArgs
.push_back("-mcode-model");
1075 CmdArgs
.push_back(A
->getValue(Args
));
1078 // Add target specific cpu and features flags.
1079 switch(getToolChain().getTriple().getArch()) {
1083 case llvm::Triple::arm
:
1084 case llvm::Triple::thumb
:
1085 AddARMTargetArgs(Args
, CmdArgs
);
1088 case llvm::Triple::mips
:
1089 case llvm::Triple::mipsel
:
1090 AddMIPSTargetArgs(Args
, CmdArgs
);
1093 case llvm::Triple::sparc
:
1094 AddSparcTargetArgs(Args
, CmdArgs
);
1097 case llvm::Triple::x86
:
1098 case llvm::Triple::x86_64
:
1099 AddX86TargetArgs(Args
, CmdArgs
);
1103 // Pass the linker version in use.
1104 if (Arg
*A
= Args
.getLastArg(options::OPT_mlinker_version_EQ
)) {
1105 CmdArgs
.push_back("-target-linker-version");
1106 CmdArgs
.push_back(A
->getValue(Args
));
1109 // -mno-omit-leaf-frame-pointer is the default on Darwin.
1110 if (Args
.hasFlag(options::OPT_momit_leaf_frame_pointer
,
1111 options::OPT_mno_omit_leaf_frame_pointer
,
1112 getToolChain().getTriple().getOS() != llvm::Triple::Darwin
))
1113 CmdArgs
.push_back("-momit-leaf-frame-pointer");
1115 // -fno-math-errno is default.
1116 if (Args
.hasFlag(options::OPT_fmath_errno
,
1117 options::OPT_fno_math_errno
,
1119 CmdArgs
.push_back("-fmath-errno");
1121 // Explicitly error on some things we know we don't support and can't just
1123 types::ID InputType
= Inputs
[0].getType();
1124 if (!Args
.hasArg(options::OPT_fallow_unsupported
)) {
1126 if ((Unsupported
= Args
.getLastArg(options::OPT_MG
)) ||
1127 (Unsupported
= Args
.getLastArg(options::OPT_iframework
)))
1128 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1129 << Unsupported
->getOption().getName();
1131 if (types::isCXX(InputType
) &&
1132 getToolChain().getTriple().getOS() == llvm::Triple::Darwin
&&
1133 getToolChain().getTriple().getArch() == llvm::Triple::x86
) {
1134 if ((Unsupported
= Args
.getLastArg(options::OPT_fapple_kext
)))
1135 D
.Diag(clang::diag::err_drv_clang_unsupported_opt_cxx_darwin_i386
)
1136 << Unsupported
->getOption().getName();
1140 Args
.AddAllArgs(CmdArgs
, options::OPT_v
);
1141 Args
.AddLastArg(CmdArgs
, options::OPT_H
);
1142 if (D
.CCPrintHeaders
) {
1143 CmdArgs
.push_back("-header-include-file");
1144 CmdArgs
.push_back(D
.CCPrintHeadersFilename
?
1145 D
.CCPrintHeadersFilename
: "-");
1147 Args
.AddLastArg(CmdArgs
, options::OPT_P
);
1148 Args
.AddLastArg(CmdArgs
, options::OPT_print_ivar_layout
);
1150 // Special case debug options to only pass -g to clang. This is
1152 Args
.ClaimAllArgs(options::OPT_g_Group
);
1153 if (Arg
*A
= Args
.getLastArg(options::OPT_g_Group
))
1154 if (!A
->getOption().matches(options::OPT_g0
))
1155 CmdArgs
.push_back("-g");
1157 Args
.AddAllArgs(CmdArgs
, options::OPT_ffunction_sections
);
1158 Args
.AddAllArgs(CmdArgs
, options::OPT_fdata_sections
);
1160 Args
.AddAllArgs(CmdArgs
, options::OPT_finstrument_functions
);
1162 Args
.AddLastArg(CmdArgs
, options::OPT_nostdinc
);
1163 Args
.AddLastArg(CmdArgs
, options::OPT_nostdincxx
);
1164 Args
.AddLastArg(CmdArgs
, options::OPT_nobuiltininc
);
1166 // Pass the path to compiler resource files.
1167 CmdArgs
.push_back("-resource-dir");
1168 CmdArgs
.push_back(D
.ResourceDir
.c_str());
1170 Args
.AddLastArg(CmdArgs
, options::OPT_working_directory
);
1172 // Add preprocessing options like -I, -D, etc. if we are using the
1175 // FIXME: Support -fpreprocessed
1176 if (types::getPreprocessedType(InputType
) != types::TY_INVALID
)
1177 AddPreprocessingOptions(D
, Args
, CmdArgs
, Output
, Inputs
);
1179 // Manually translate -O to -O2 and -O4 to -O3; let clang reject
1181 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
)) {
1182 if (A
->getOption().matches(options::OPT_O4
))
1183 CmdArgs
.push_back("-O3");
1184 else if (A
->getOption().matches(options::OPT_O
) &&
1185 A
->getValue(Args
)[0] == '\0')
1186 CmdArgs
.push_back("-O2");
1187 else if (A
->getOption().matches(options::OPT_O
) &&
1188 A
->getValue(Args
)[0] == 'z' &&
1189 A
->getValue(Args
)[1] == '\0')
1190 CmdArgs
.push_back("-Os");
1192 A
->render(Args
, CmdArgs
);
1195 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
);
1196 Args
.AddLastArg(CmdArgs
, options::OPT_pedantic
);
1197 Args
.AddLastArg(CmdArgs
, options::OPT_pedantic_errors
);
1198 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
1200 // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi}
1201 // (-ansi is equivalent to -std=c89).
1203 // If a std is supplied, only add -trigraphs if it follows the
1205 if (Arg
*Std
= Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
1206 if (Std
->getOption().matches(options::OPT_ansi
))
1207 if (types::isCXX(InputType
))
1208 CmdArgs
.push_back("-std=c++98");
1210 CmdArgs
.push_back("-std=c89");
1212 Std
->render(Args
, CmdArgs
);
1214 if (Arg
*A
= Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
,
1215 options::OPT_trigraphs
))
1217 A
->render(Args
, CmdArgs
);
1219 // Honor -std-default.
1221 // FIXME: Clang doesn't correctly handle -std= when the input language
1222 // doesn't match. For the time being just ignore this for C++ inputs;
1223 // eventually we want to do all the standard defaulting here instead of
1224 // splitting it between the driver and clang -cc1.
1225 if (!types::isCXX(InputType
))
1226 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
1227 "-std=", /*Joined=*/true);
1228 Args
.AddLastArg(CmdArgs
, options::OPT_trigraphs
);
1231 // Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'.
1232 if (Arg
*Asm
= Args
.getLastArg(options::OPT_fasm
, options::OPT_fno_asm
)) {
1233 if (Asm
->getOption().matches(options::OPT_fasm
))
1234 CmdArgs
.push_back("-fgnu-keywords");
1236 CmdArgs
.push_back("-fno-gnu-keywords");
1239 if (Arg
*A
= Args
.getLastArg(options::OPT_ftemplate_depth_
)) {
1240 CmdArgs
.push_back("-ftemplate-depth");
1241 CmdArgs
.push_back(A
->getValue(Args
));
1244 if (Arg
*A
= Args
.getLastArg(options::OPT_Wlarge_by_value_copy_EQ
,
1245 options::OPT_Wlarge_by_value_copy_def
)) {
1246 CmdArgs
.push_back("-Wlarge-by-value-copy");
1247 if (A
->getNumValues())
1248 CmdArgs
.push_back(A
->getValue(Args
));
1250 CmdArgs
.push_back("64"); // default value for -Wlarge-by-value-copy.
1253 if (Args
.hasArg(options::OPT__relocatable_pch
))
1254 CmdArgs
.push_back("-relocatable-pch");
1256 if (Arg
*A
= Args
.getLastArg(options::OPT_fconstant_string_class_EQ
)) {
1257 CmdArgs
.push_back("-fconstant-string-class");
1258 CmdArgs
.push_back(A
->getValue(Args
));
1261 if (Arg
*A
= Args
.getLastArg(options::OPT_ftabstop_EQ
)) {
1262 CmdArgs
.push_back("-ftabstop");
1263 CmdArgs
.push_back(A
->getValue(Args
));
1266 CmdArgs
.push_back("-ferror-limit");
1267 if (Arg
*A
= Args
.getLastArg(options::OPT_ferror_limit_EQ
))
1268 CmdArgs
.push_back(A
->getValue(Args
));
1270 CmdArgs
.push_back("19");
1272 if (Arg
*A
= Args
.getLastArg(options::OPT_fmacro_backtrace_limit_EQ
)) {
1273 CmdArgs
.push_back("-fmacro-backtrace-limit");
1274 CmdArgs
.push_back(A
->getValue(Args
));
1277 if (Arg
*A
= Args
.getLastArg(options::OPT_ftemplate_backtrace_limit_EQ
)) {
1278 CmdArgs
.push_back("-ftemplate-backtrace-limit");
1279 CmdArgs
.push_back(A
->getValue(Args
));
1282 // Pass -fmessage-length=.
1283 CmdArgs
.push_back("-fmessage-length");
1284 if (Arg
*A
= Args
.getLastArg(options::OPT_fmessage_length_EQ
)) {
1285 CmdArgs
.push_back(A
->getValue(Args
));
1287 // If -fmessage-length=N was not specified, determine whether this is a
1288 // terminal and, if so, implicitly define -fmessage-length appropriately.
1289 unsigned N
= llvm::sys::Process::StandardErrColumns();
1290 CmdArgs
.push_back(Args
.MakeArgString(llvm::Twine(N
)));
1293 if (const Arg
*A
= Args
.getLastArg(options::OPT_fvisibility_EQ
)) {
1294 CmdArgs
.push_back("-fvisibility");
1295 CmdArgs
.push_back(A
->getValue(Args
));
1298 Args
.AddLastArg(CmdArgs
, options::OPT_fvisibility_inlines_hidden
);
1300 // -fhosted is default.
1301 if (KernelOrKext
|| Args
.hasFlag(options::OPT_ffreestanding
,
1302 options::OPT_fhosted
,
1304 CmdArgs
.push_back("-ffreestanding");
1306 // Forward -f (flag) options which we can pass directly.
1307 Args
.AddLastArg(CmdArgs
, options::OPT_fcatch_undefined_behavior
);
1308 Args
.AddLastArg(CmdArgs
, options::OPT_femit_all_decls
);
1309 Args
.AddLastArg(CmdArgs
, options::OPT_fheinous_gnu_extensions
);
1310 Args
.AddLastArg(CmdArgs
, options::OPT_flimit_debug_info
);
1312 // -flax-vector-conversions is default.
1313 if (!Args
.hasFlag(options::OPT_flax_vector_conversions
,
1314 options::OPT_fno_lax_vector_conversions
))
1315 CmdArgs
.push_back("-fno-lax-vector-conversions");
1317 // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only
1318 // takes precedence.
1319 const Arg
*GCArg
= Args
.getLastArg(options::OPT_fobjc_gc_only
);
1321 GCArg
= Args
.getLastArg(options::OPT_fobjc_gc
);
1323 if (getToolChain().SupportsObjCGC()) {
1324 GCArg
->render(Args
, CmdArgs
);
1326 // FIXME: We should move this to a hard error.
1327 D
.Diag(clang::diag::warn_drv_objc_gc_unsupported
)
1328 << GCArg
->getAsString(Args
);
1332 if (Args
.getLastArg(options::OPT_fapple_kext
))
1333 CmdArgs
.push_back("-fapple-kext");
1335 Args
.AddLastArg(CmdArgs
, options::OPT_fno_show_column
);
1336 Args
.AddLastArg(CmdArgs
, options::OPT_fobjc_sender_dependent_dispatch
);
1337 Args
.AddLastArg(CmdArgs
, options::OPT_fdiagnostics_print_source_range_info
);
1338 Args
.AddLastArg(CmdArgs
, options::OPT_fdiagnostics_parseable_fixits
);
1339 Args
.AddLastArg(CmdArgs
, options::OPT_ftime_report
);
1340 Args
.AddLastArg(CmdArgs
, options::OPT_ftrapv
);
1342 if (Arg
*A
= Args
.getLastArg(options::OPT_ftrapv_handler_EQ
)) {
1343 CmdArgs
.push_back("-ftrapv-handler");
1344 CmdArgs
.push_back(A
->getValue(Args
));
1347 Args
.AddLastArg(CmdArgs
, options::OPT_fwrapv
);
1348 Args
.AddLastArg(CmdArgs
, options::OPT_fwritable_strings
);
1349 Args
.AddLastArg(CmdArgs
, options::OPT_funroll_loops
);
1351 Args
.AddLastArg(CmdArgs
, options::OPT_pthread
);
1353 // -stack-protector=0 is default.
1354 unsigned StackProtectorLevel
= 0;
1355 if (Arg
*A
= Args
.getLastArg(options::OPT_fno_stack_protector
,
1356 options::OPT_fstack_protector_all
,
1357 options::OPT_fstack_protector
)) {
1358 if (A
->getOption().matches(options::OPT_fstack_protector
))
1359 StackProtectorLevel
= 1;
1360 else if (A
->getOption().matches(options::OPT_fstack_protector_all
))
1361 StackProtectorLevel
= 2;
1363 StackProtectorLevel
= getToolChain().GetDefaultStackProtectorLevel();
1364 if (StackProtectorLevel
) {
1365 CmdArgs
.push_back("-stack-protector");
1366 CmdArgs
.push_back(Args
.MakeArgString(llvm::Twine(StackProtectorLevel
)));
1369 // Forward -f options with positive and negative forms; we translate
1372 if (Args
.hasArg(options::OPT_mkernel
)) {
1373 if (!Args
.hasArg(options::OPT_fapple_kext
) && types::isCXX(InputType
))
1374 CmdArgs
.push_back("-fapple-kext");
1375 if (!Args
.hasArg(options::OPT_fbuiltin
))
1376 CmdArgs
.push_back("-fno-builtin");
1378 // -fbuiltin is default.
1379 else if (!Args
.hasFlag(options::OPT_fbuiltin
, options::OPT_fno_builtin
))
1380 CmdArgs
.push_back("-fno-builtin");
1382 if (!Args
.hasFlag(options::OPT_fassume_sane_operator_new
,
1383 options::OPT_fno_assume_sane_operator_new
))
1384 CmdArgs
.push_back("-fno-assume-sane-operator-new");
1386 // -fblocks=0 is default.
1387 if (Args
.hasFlag(options::OPT_fblocks
, options::OPT_fno_blocks
,
1388 getToolChain().IsBlocksDefault())) {
1389 CmdArgs
.push_back("-fblocks");
1392 // -faccess-control is default.
1393 if (Args
.hasFlag(options::OPT_fno_access_control
,
1394 options::OPT_faccess_control
,
1396 CmdArgs
.push_back("-fno-access-control");
1398 // -felide-constructors is the default.
1399 if (Args
.hasFlag(options::OPT_fno_elide_constructors
,
1400 options::OPT_felide_constructors
,
1402 CmdArgs
.push_back("-fno-elide-constructors");
1404 // -fexceptions=0 is default.
1405 if (!KernelOrKext
&&
1406 needsExceptions(Args
, InputType
, getToolChain().getTriple()))
1407 CmdArgs
.push_back("-fexceptions");
1409 if (getToolChain().UseSjLjExceptions())
1410 CmdArgs
.push_back("-fsjlj-exceptions");
1412 // -frtti is default.
1414 !Args
.hasFlag(options::OPT_frtti
, options::OPT_fno_rtti
))
1415 CmdArgs
.push_back("-fno-rtti");
1417 // -fshort-enums=0 is default.
1418 // FIXME: Are there targers where -fshort-enums is on by default ?
1419 if (Args
.hasFlag(options::OPT_fshort_enums
,
1420 options::OPT_fno_short_enums
, false))
1421 CmdArgs
.push_back("-fshort-enums");
1423 // -fsigned-char is default.
1424 if (!Args
.hasFlag(options::OPT_fsigned_char
, options::OPT_funsigned_char
,
1425 isSignedCharDefault(getToolChain().getTriple())))
1426 CmdArgs
.push_back("-fno-signed-char");
1428 // -fthreadsafe-static is default.
1429 if (!Args
.hasFlag(options::OPT_fthreadsafe_statics
,
1430 options::OPT_fno_threadsafe_statics
))
1431 CmdArgs
.push_back("-fno-threadsafe-statics");
1433 // -fuse-cxa-atexit is default.
1435 !Args
.hasFlag(options::OPT_fuse_cxa_atexit
, options::OPT_fno_use_cxa_atexit
,
1436 getToolChain().getTriple().getOS() != llvm::Triple::Cygwin
&&
1437 getToolChain().getTriple().getOS() != llvm::Triple::MinGW32
&&
1438 getToolChain().getTriple().getOS() != llvm::Triple::MinGW64
))
1439 CmdArgs
.push_back("-fno-use-cxa-atexit");
1441 // -fms-extensions=0 is default.
1442 if (Args
.hasFlag(options::OPT_fms_extensions
, options::OPT_fno_ms_extensions
,
1443 getToolChain().getTriple().getOS() == llvm::Triple::Win32
))
1444 CmdArgs
.push_back("-fms-extensions");
1446 // -fmsc-version=1300 is default.
1447 if (Args
.hasFlag(options::OPT_fms_extensions
, options::OPT_fno_ms_extensions
,
1448 getToolChain().getTriple().getOS() == llvm::Triple::Win32
) ||
1449 Args
.hasArg(options::OPT_fmsc_version
)) {
1450 llvm::StringRef msc_ver
= Args
.getLastArgValue(options::OPT_fmsc_version
);
1451 if (msc_ver
.empty())
1452 CmdArgs
.push_back("-fmsc-version=1300");
1454 CmdArgs
.push_back(Args
.MakeArgString("-fmsc-version=" + msc_ver
));
1458 // -fborland-extensions=0 is default.
1459 if (Args
.hasFlag(options::OPT_fborland_extensions
,
1460 options::OPT_fno_borland_extensions
, false))
1461 CmdArgs
.push_back("-fborland-extensions");
1463 // -fgnu-keywords default varies depending on language; only pass if
1465 if (Arg
*A
= Args
.getLastArg(options::OPT_fgnu_keywords
,
1466 options::OPT_fno_gnu_keywords
))
1467 A
->render(Args
, CmdArgs
);
1469 // -fnext-runtime defaults to on Darwin and when rewriting Objective-C, and is
1470 // -the -cc1 default.
1471 bool NeXTRuntimeIsDefault
=
1472 IsRewriter
|| getToolChain().getTriple().getOS() == llvm::Triple::Darwin
;
1473 if (!Args
.hasFlag(options::OPT_fnext_runtime
, options::OPT_fgnu_runtime
,
1474 NeXTRuntimeIsDefault
))
1475 CmdArgs
.push_back("-fgnu-runtime");
1477 // -fobjc-nonfragile-abi=0 is default.
1478 if (types::isObjC(InputType
)) {
1479 // Compute the Objective-C ABI "version" to use. Version numbers are
1480 // slightly confusing for historical reasons:
1481 // 1 - Traditional "fragile" ABI
1482 // 2 - Non-fragile ABI, version 1
1483 // 3 - Non-fragile ABI, version 2
1484 unsigned Version
= 1;
1485 // If -fobjc-abi-version= is present, use that to set the version.
1486 if (Arg
*A
= Args
.getLastArg(options::OPT_fobjc_abi_version_EQ
)) {
1487 if (llvm::StringRef(A
->getValue(Args
)) == "1")
1489 else if (llvm::StringRef(A
->getValue(Args
)) == "2")
1491 else if (llvm::StringRef(A
->getValue(Args
)) == "3")
1494 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
1496 // Otherwise, determine if we are using the non-fragile ABI.
1497 if (Args
.hasFlag(options::OPT_fobjc_nonfragile_abi
,
1498 options::OPT_fno_objc_nonfragile_abi
,
1499 getToolChain().IsObjCNonFragileABIDefault())) {
1500 // Determine the non-fragile ABI version to use.
1501 #ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO
1502 unsigned NonFragileABIVersion
= 1;
1504 unsigned NonFragileABIVersion
= 2;
1507 if (Arg
*A
= Args
.getLastArg(
1508 options::OPT_fobjc_nonfragile_abi_version_EQ
)) {
1509 if (llvm::StringRef(A
->getValue(Args
)) == "1")
1510 NonFragileABIVersion
= 1;
1511 else if (llvm::StringRef(A
->getValue(Args
)) == "2")
1512 NonFragileABIVersion
= 2;
1514 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1515 << A
->getAsString(Args
);
1518 Version
= 1 + NonFragileABIVersion
;
1524 if (Version
== 2 || Version
== 3) {
1525 CmdArgs
.push_back("-fobjc-nonfragile-abi");
1527 // -fobjc-dispatch-method is only relevant with the nonfragile-abi, and
1528 // legacy is the default.
1529 if (!Args
.hasFlag(options::OPT_fobjc_legacy_dispatch
,
1530 options::OPT_fno_objc_legacy_dispatch
,
1531 getToolChain().IsObjCLegacyDispatchDefault())) {
1532 if (getToolChain().UseObjCMixedDispatch())
1533 CmdArgs
.push_back("-fobjc-dispatch-method=mixed");
1535 CmdArgs
.push_back("-fobjc-dispatch-method=non-legacy");
1539 // -fobjc-default-synthesize-properties=0 is default.
1540 if (Args
.hasFlag(options::OPT_fobjc_default_synthesize_properties
,
1541 options::OPT_fno_objc_default_synthesize_properties
,
1542 getToolChain().IsObjCDefaultSynthPropertiesDefault())) {
1543 CmdArgs
.push_back("-fobjc-default-synthesize-properties");
1547 if (!Args
.hasFlag(options::OPT_fassume_sane_operator_new
,
1548 options::OPT_fno_assume_sane_operator_new
))
1549 CmdArgs
.push_back("-fno-assume-sane-operator-new");
1551 // -fconstant-cfstrings is default, and may be subject to argument translation
1553 if (!Args
.hasFlag(options::OPT_fconstant_cfstrings
,
1554 options::OPT_fno_constant_cfstrings
) ||
1555 !Args
.hasFlag(options::OPT_mconstant_cfstrings
,
1556 options::OPT_mno_constant_cfstrings
))
1557 CmdArgs
.push_back("-fno-constant-cfstrings");
1559 // -fshort-wchar default varies depending on platform; only
1560 // pass if specified.
1561 if (Arg
*A
= Args
.getLastArg(options::OPT_fshort_wchar
))
1562 A
->render(Args
, CmdArgs
);
1564 // -fno-pascal-strings is default, only pass non-default. If the tool chain
1565 // happened to translate to -mpascal-strings, we want to back translate here.
1567 // FIXME: This is gross; that translation should be pulled from the
1569 if (Args
.hasFlag(options::OPT_fpascal_strings
,
1570 options::OPT_fno_pascal_strings
,
1572 Args
.hasFlag(options::OPT_mpascal_strings
,
1573 options::OPT_mno_pascal_strings
,
1575 CmdArgs
.push_back("-fpascal-strings");
1577 if (Args
.hasArg(options::OPT_mkernel
) ||
1578 Args
.hasArg(options::OPT_fapple_kext
)) {
1579 if (!Args
.hasArg(options::OPT_fcommon
))
1580 CmdArgs
.push_back("-fno-common");
1582 // -fcommon is default, only pass non-default.
1583 else if (!Args
.hasFlag(options::OPT_fcommon
, options::OPT_fno_common
))
1584 CmdArgs
.push_back("-fno-common");
1586 // -fsigned-bitfields is default, and clang doesn't yet support
1587 // -funsigned-bitfields.
1588 if (!Args
.hasFlag(options::OPT_fsigned_bitfields
,
1589 options::OPT_funsigned_bitfields
))
1590 D
.Diag(clang::diag::warn_drv_clang_unsupported
)
1591 << Args
.getLastArg(options::OPT_funsigned_bitfields
)->getAsString(Args
);
1593 // -fsigned-bitfields is default, and clang doesn't support -fno-for-scope.
1594 if (!Args
.hasFlag(options::OPT_ffor_scope
,
1595 options::OPT_fno_for_scope
))
1596 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1597 << Args
.getLastArg(options::OPT_fno_for_scope
)->getAsString(Args
);
1599 // -fcaret-diagnostics is default.
1600 if (!Args
.hasFlag(options::OPT_fcaret_diagnostics
,
1601 options::OPT_fno_caret_diagnostics
, true))
1602 CmdArgs
.push_back("-fno-caret-diagnostics");
1604 // -fdiagnostics-fixit-info is default, only pass non-default.
1605 if (!Args
.hasFlag(options::OPT_fdiagnostics_fixit_info
,
1606 options::OPT_fno_diagnostics_fixit_info
))
1607 CmdArgs
.push_back("-fno-diagnostics-fixit-info");
1609 // Enable -fdiagnostics-show-option by default.
1610 if (Args
.hasFlag(options::OPT_fdiagnostics_show_option
,
1611 options::OPT_fno_diagnostics_show_option
))
1612 CmdArgs
.push_back("-fdiagnostics-show-option");
1615 Args
.getLastArg(options::OPT_fdiagnostics_show_category_EQ
)) {
1616 CmdArgs
.push_back("-fdiagnostics-show-category");
1617 CmdArgs
.push_back(A
->getValue(Args
));
1620 // Color diagnostics are the default, unless the terminal doesn't support
1622 if (Args
.hasFlag(options::OPT_fcolor_diagnostics
,
1623 options::OPT_fno_color_diagnostics
,
1624 llvm::sys::Process::StandardErrHasColors()))
1625 CmdArgs
.push_back("-fcolor-diagnostics");
1627 if (!Args
.hasFlag(options::OPT_fshow_source_location
,
1628 options::OPT_fno_show_source_location
))
1629 CmdArgs
.push_back("-fno-show-source-location");
1631 if (!Args
.hasFlag(options::OPT_fspell_checking
,
1632 options::OPT_fno_spell_checking
))
1633 CmdArgs
.push_back("-fno-spell-checking");
1636 // Silently ignore -fasm-blocks for now.
1637 (void) Args
.hasFlag(options::OPT_fasm_blocks
, options::OPT_fno_asm_blocks
,
1640 if (Arg
*A
= Args
.getLastArg(options::OPT_fshow_overloads_EQ
))
1641 A
->render(Args
, CmdArgs
);
1643 // -fdollars-in-identifiers default varies depending on platform and
1644 // language; only pass if specified.
1645 if (Arg
*A
= Args
.getLastArg(options::OPT_fdollars_in_identifiers
,
1646 options::OPT_fno_dollars_in_identifiers
)) {
1647 if (A
->getOption().matches(options::OPT_fdollars_in_identifiers
))
1648 CmdArgs
.push_back("-fdollars-in-identifiers");
1650 CmdArgs
.push_back("-fno-dollars-in-identifiers");
1653 // -funit-at-a-time is default, and we don't support -fno-unit-at-a-time for
1654 // practical purposes.
1655 if (Arg
*A
= Args
.getLastArg(options::OPT_funit_at_a_time
,
1656 options::OPT_fno_unit_at_a_time
)) {
1657 if (A
->getOption().matches(options::OPT_fno_unit_at_a_time
))
1658 D
.Diag(clang::diag::warn_drv_clang_unsupported
) << A
->getAsString(Args
);
1661 // Default to -fno-builtin-str{cat,cpy} on Darwin for ARM.
1663 // FIXME: This is disabled until clang -cc1 supports -fno-builtin-foo. PR4941.
1665 if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin
&&
1666 (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
1667 getToolChain().getTriple().getArch() == llvm::Triple::thumb
)) {
1668 if (!Args
.hasArg(options::OPT_fbuiltin_strcat
))
1669 CmdArgs
.push_back("-fno-builtin-strcat");
1670 if (!Args
.hasArg(options::OPT_fbuiltin_strcpy
))
1671 CmdArgs
.push_back("-fno-builtin-strcpy");
1675 if (Arg
*A
= Args
.getLastArg(options::OPT_traditional
,
1676 options::OPT_traditional_cpp
))
1677 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
1679 Args
.AddLastArg(CmdArgs
, options::OPT_dM
);
1680 Args
.AddLastArg(CmdArgs
, options::OPT_dD
);
1682 // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
1684 Args
.AddAllArgValues(CmdArgs
, options::OPT_Xclang
);
1685 for (arg_iterator it
= Args
.filtered_begin(options::OPT_mllvm
),
1686 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
1689 // We translate this by hand to the -cc1 argument, since nightly test uses
1690 // it and developers have been trained to spell it with -mllvm.
1691 if (llvm::StringRef((*it
)->getValue(Args
, 0)) == "-disable-llvm-optzns")
1692 CmdArgs
.push_back("-disable-llvm-optzns");
1694 (*it
)->render(Args
, CmdArgs
);
1697 if (Output
.getType() == types::TY_Dependencies
) {
1698 // Handled with other dependency code.
1699 } else if (Output
.isFilename()) {
1700 CmdArgs
.push_back("-o");
1701 CmdArgs
.push_back(Output
.getFilename());
1703 assert(Output
.isNothing() && "Invalid output.");
1706 for (InputInfoList::const_iterator
1707 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
1708 const InputInfo
&II
= *it
;
1709 CmdArgs
.push_back("-x");
1710 CmdArgs
.push_back(types::getTypeName(II
.getType()));
1711 if (II
.isFilename())
1712 CmdArgs
.push_back(II
.getFilename());
1714 II
.getInputArg().renderAsInput(Args
, CmdArgs
);
1717 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
1719 const char *Exec
= getToolChain().getDriver().getClangProgramPath();
1721 // Optionally embed the -cc1 level arguments into the debug info, for build
1723 if (getToolChain().UseDwarfDebugFlags()) {
1724 ArgStringList OriginalArgs
;
1725 for (ArgList::const_iterator it
= Args
.begin(),
1726 ie
= Args
.end(); it
!= ie
; ++it
)
1727 (*it
)->render(Args
, OriginalArgs
);
1729 llvm::SmallString
<256> Flags
;
1731 for (unsigned i
= 0, e
= OriginalArgs
.size(); i
!= e
; ++i
) {
1733 Flags
+= OriginalArgs
[i
];
1735 CmdArgs
.push_back("-dwarf-debug-flags");
1736 CmdArgs
.push_back(Args
.MakeArgString(Flags
.str()));
1739 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1741 // Explicitly warn that these options are unsupported, even though
1742 // we are allowing compilation to continue.
1743 for (arg_iterator it
= Args
.filtered_begin(options::OPT_pg
),
1744 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
1746 D
.Diag(clang::diag::warn_drv_clang_unsupported
) << (*it
)->getAsString(Args
);
1749 // Claim some arguments which clang supports automatically.
1751 // -fpch-preprocess is used with gcc to add a special marker in the output to
1752 // include the PCH file. Clang's PTH solution is completely transparent, so we
1753 // do not need to deal with it at all.
1754 Args
.ClaimAllArgs(options::OPT_fpch_preprocess
);
1756 // Claim some arguments which clang doesn't support, but we don't
1757 // care to warn the user about.
1758 Args
.ClaimAllArgs(options::OPT_clang_ignored_f_Group
);
1759 Args
.ClaimAllArgs(options::OPT_clang_ignored_m_Group
);
1762 void ClangAs::ConstructJob(Compilation
&C
, const JobAction
&JA
,
1763 const InputInfo
&Output
,
1764 const InputInfoList
&Inputs
,
1765 const ArgList
&Args
,
1766 const char *LinkingOutput
) const {
1767 ArgStringList CmdArgs
;
1769 assert(Inputs
.size() == 1 && "Unexpected number of inputs.");
1770 const InputInfo
&Input
= Inputs
[0];
1772 // Don't warn about "clang -w -c foo.s"
1773 Args
.ClaimAllArgs(options::OPT_w
);
1775 // Invoke ourselves in -cc1as mode.
1777 // FIXME: Implement custom jobs for internal actions.
1778 CmdArgs
.push_back("-cc1as");
1780 // Add the "effective" target triple.
1781 CmdArgs
.push_back("-triple");
1782 std::string TripleStr
= getToolChain().ComputeEffectiveClangTriple(Args
);
1783 CmdArgs
.push_back(Args
.MakeArgString(TripleStr
));
1785 // Set the output mode, we currently only expect to be used as a real
1787 CmdArgs
.push_back("-filetype");
1788 CmdArgs
.push_back("obj");
1790 // At -O0, we use -mrelax-all by default.
1792 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
))
1793 IsOpt
= !A
->getOption().matches(options::OPT_O0
);
1794 if (Args
.hasFlag(options::OPT_mrelax_all
,
1795 options::OPT_mno_relax_all
,
1797 CmdArgs
.push_back("-relax-all");
1799 // FIXME: Add -force_cpusubtype_ALL support, once we have it.
1801 // FIXME: Add -g support, once we have it.
1803 // FIXME: Add -static support, once we have it.
1805 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
1806 options::OPT_Xassembler
);
1808 assert(Output
.isFilename() && "Unexpected lipo output.");
1809 CmdArgs
.push_back("-o");
1810 CmdArgs
.push_back(Output
.getFilename());
1812 assert(Input
.isFilename() && "Invalid input.");
1813 CmdArgs
.push_back(Input
.getFilename());
1815 const char *Exec
= getToolChain().getDriver().getClangProgramPath();
1816 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1819 void gcc::Common::ConstructJob(Compilation
&C
, const JobAction
&JA
,
1820 const InputInfo
&Output
,
1821 const InputInfoList
&Inputs
,
1822 const ArgList
&Args
,
1823 const char *LinkingOutput
) const {
1824 const Driver
&D
= getToolChain().getDriver();
1825 ArgStringList CmdArgs
;
1827 for (ArgList::const_iterator
1828 it
= Args
.begin(), ie
= Args
.end(); it
!= ie
; ++it
) {
1830 if (A
->getOption().hasForwardToGCC()) {
1831 // Don't forward any -g arguments to assembly steps.
1832 if (isa
<AssembleJobAction
>(JA
) &&
1833 A
->getOption().matches(options::OPT_g_Group
))
1836 // It is unfortunate that we have to claim here, as this means
1837 // we will basically never report anything interesting for
1838 // platforms using a generic gcc, even if we are just using gcc
1839 // to get to the assembler.
1841 A
->render(Args
, CmdArgs
);
1845 RenderExtraToolArgs(JA
, CmdArgs
);
1847 // If using a driver driver, force the arch.
1848 const std::string
&Arch
= getToolChain().getArchName();
1849 if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin
) {
1850 CmdArgs
.push_back("-arch");
1852 // FIXME: Remove these special cases.
1853 if (Arch
== "powerpc")
1854 CmdArgs
.push_back("ppc");
1855 else if (Arch
== "powerpc64")
1856 CmdArgs
.push_back("ppc64");
1858 CmdArgs
.push_back(Args
.MakeArgString(Arch
));
1861 // Try to force gcc to match the tool chain we want, if we recognize
1864 // FIXME: The triple class should directly provide the information we want
1866 if (Arch
== "i386" || Arch
== "powerpc")
1867 CmdArgs
.push_back("-m32");
1868 else if (Arch
== "x86_64" || Arch
== "powerpc64")
1869 CmdArgs
.push_back("-m64");
1871 if (Output
.isFilename()) {
1872 CmdArgs
.push_back("-o");
1873 CmdArgs
.push_back(Output
.getFilename());
1875 assert(Output
.isNothing() && "Unexpected output");
1876 CmdArgs
.push_back("-fsyntax-only");
1880 // Only pass -x if gcc will understand it; otherwise hope gcc
1881 // understands the suffix correctly. The main use case this would go
1882 // wrong in is for linker inputs if they happened to have an odd
1883 // suffix; really the only way to get this to happen is a command
1884 // like '-x foobar a.c' which will treat a.c like a linker input.
1886 // FIXME: For the linker case specifically, can we safely convert
1887 // inputs into '-Wl,' options?
1888 for (InputInfoList::const_iterator
1889 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
1890 const InputInfo
&II
= *it
;
1892 // Don't try to pass LLVM or AST inputs to a generic gcc.
1893 if (II
.getType() == types::TY_LLVM_IR
|| II
.getType() == types::TY_LTO_IR
||
1894 II
.getType() == types::TY_LLVM_BC
|| II
.getType() == types::TY_LTO_BC
)
1895 D
.Diag(clang::diag::err_drv_no_linker_llvm_support
)
1896 << getToolChain().getTripleString();
1897 else if (II
.getType() == types::TY_AST
)
1898 D
.Diag(clang::diag::err_drv_no_ast_support
)
1899 << getToolChain().getTripleString();
1901 if (types::canTypeBeUserSpecified(II
.getType())) {
1902 CmdArgs
.push_back("-x");
1903 CmdArgs
.push_back(types::getTypeName(II
.getType()));
1906 if (II
.isFilename())
1907 CmdArgs
.push_back(II
.getFilename());
1909 const Arg
&A
= II
.getInputArg();
1911 // Reverse translate some rewritten options.
1912 if (A
.getOption().matches(options::OPT_Z_reserved_lib_stdcxx
)) {
1913 CmdArgs
.push_back("-lstdc++");
1917 // Don't render as input, we need gcc to do the translations.
1918 A
.render(Args
, CmdArgs
);
1922 const char *GCCName
= getToolChain().getDriver().getCCCGenericGCCName().c_str();
1924 Args
.MakeArgString(getToolChain().GetProgramPath(GCCName
));
1925 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1928 void gcc::Preprocess::RenderExtraToolArgs(const JobAction
&JA
,
1929 ArgStringList
&CmdArgs
) const {
1930 CmdArgs
.push_back("-E");
1933 void gcc::Precompile::RenderExtraToolArgs(const JobAction
&JA
,
1934 ArgStringList
&CmdArgs
) const {
1935 // The type is good enough.
1938 void gcc::Compile::RenderExtraToolArgs(const JobAction
&JA
,
1939 ArgStringList
&CmdArgs
) const {
1940 const Driver
&D
= getToolChain().getDriver();
1942 // If -flto, etc. are present then make sure not to force assembly output.
1943 if (JA
.getType() == types::TY_LLVM_IR
|| JA
.getType() == types::TY_LTO_IR
||
1944 JA
.getType() == types::TY_LLVM_BC
|| JA
.getType() == types::TY_LTO_BC
)
1945 CmdArgs
.push_back("-c");
1947 if (JA
.getType() != types::TY_PP_Asm
)
1948 D
.Diag(clang::diag::err_drv_invalid_gcc_output_type
)
1949 << getTypeName(JA
.getType());
1951 CmdArgs
.push_back("-S");
1955 void gcc::Assemble::RenderExtraToolArgs(const JobAction
&JA
,
1956 ArgStringList
&CmdArgs
) const {
1957 CmdArgs
.push_back("-c");
1960 void gcc::Link::RenderExtraToolArgs(const JobAction
&JA
,
1961 ArgStringList
&CmdArgs
) const {
1962 // The types are (hopefully) good enough.
1965 const char *darwin::CC1::getCC1Name(types::ID Type
) const {
1968 assert(0 && "Unexpected type for Darwin CC1 tool.");
1970 case types::TY_C
: case types::TY_CHeader
:
1971 case types::TY_PP_C
: case types::TY_PP_CHeader
:
1973 case types::TY_ObjC
: case types::TY_ObjCHeader
:
1974 case types::TY_PP_ObjC
: case types::TY_PP_ObjCHeader
:
1976 case types::TY_CXX
: case types::TY_CXXHeader
:
1977 case types::TY_PP_CXX
: case types::TY_PP_CXXHeader
:
1979 case types::TY_ObjCXX
: case types::TY_ObjCXXHeader
:
1980 case types::TY_PP_ObjCXX
: case types::TY_PP_ObjCXXHeader
:
1981 return "cc1objplus";
1985 const char *darwin::CC1::getBaseInputName(const ArgList
&Args
,
1986 const InputInfoList
&Inputs
) {
1987 return Args
.MakeArgString(
1988 llvm::sys::path::filename(Inputs
[0].getBaseInput()));
1991 const char *darwin::CC1::getBaseInputStem(const ArgList
&Args
,
1992 const InputInfoList
&Inputs
) {
1993 const char *Str
= getBaseInputName(Args
, Inputs
);
1995 if (const char *End
= strrchr(Str
, '.'))
1996 return Args
.MakeArgString(std::string(Str
, End
));
2002 darwin::CC1::getDependencyFileName(const ArgList
&Args
,
2003 const InputInfoList
&Inputs
) {
2004 // FIXME: Think about this more.
2007 if (Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
)) {
2008 std::string
Str(OutputOpt
->getValue(Args
));
2010 Res
= Str
.substr(0, Str
.rfind('.'));
2012 Res
= darwin::CC1::getBaseInputStem(Args
, Inputs
);
2014 return Args
.MakeArgString(Res
+ ".d");
2017 void darwin::CC1::AddCC1Args(const ArgList
&Args
,
2018 ArgStringList
&CmdArgs
) const {
2019 const Driver
&D
= getToolChain().getDriver();
2021 CheckCodeGenerationOptions(D
, Args
);
2023 // Derived from cc1 spec.
2024 if (!Args
.hasArg(options::OPT_mkernel
) && !Args
.hasArg(options::OPT_static
) &&
2025 !Args
.hasArg(options::OPT_mdynamic_no_pic
))
2026 CmdArgs
.push_back("-fPIC");
2028 if (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
2029 getToolChain().getTriple().getArch() == llvm::Triple::thumb
) {
2030 if (!Args
.hasArg(options::OPT_fbuiltin_strcat
))
2031 CmdArgs
.push_back("-fno-builtin-strcat");
2032 if (!Args
.hasArg(options::OPT_fbuiltin_strcpy
))
2033 CmdArgs
.push_back("-fno-builtin-strcpy");
2036 // gcc has some code here to deal with when no -mmacosx-version-min
2037 // and no -miphoneos-version-min is present, but this never happens
2038 // due to tool chain specific argument translation.
2040 if (Args
.hasArg(options::OPT_g_Flag
) &&
2041 !Args
.hasArg(options::OPT_fno_eliminate_unused_debug_symbols
))
2042 CmdArgs
.push_back("-feliminate-unused-debug-symbols");
2045 void darwin::CC1::AddCC1OptionsArgs(const ArgList
&Args
, ArgStringList
&CmdArgs
,
2046 const InputInfoList
&Inputs
,
2047 const ArgStringList
&OutputArgs
) const {
2048 const Driver
&D
= getToolChain().getDriver();
2050 // Derived from cc1_options spec.
2051 if (Args
.hasArg(options::OPT_fast
) ||
2052 Args
.hasArg(options::OPT_fastf
) ||
2053 Args
.hasArg(options::OPT_fastcp
))
2054 CmdArgs
.push_back("-O3");
2056 if (Arg
*A
= Args
.getLastArg(options::OPT_pg
))
2057 if (Args
.hasArg(options::OPT_fomit_frame_pointer
))
2058 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
2059 << A
->getAsString(Args
) << "-fomit-frame-pointer";
2061 AddCC1Args(Args
, CmdArgs
);
2063 if (!Args
.hasArg(options::OPT_Q
))
2064 CmdArgs
.push_back("-quiet");
2066 CmdArgs
.push_back("-dumpbase");
2067 CmdArgs
.push_back(darwin::CC1::getBaseInputName(Args
, Inputs
));
2069 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Group
);
2071 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Group
);
2072 Args
.AddAllArgs(CmdArgs
, options::OPT_a_Group
);
2074 // FIXME: The goal is to use the user provided -o if that is our
2075 // final output, otherwise to drive from the original input
2076 // name. Find a clean way to go about this.
2077 if ((Args
.hasArg(options::OPT_c
) || Args
.hasArg(options::OPT_S
)) &&
2078 Args
.hasArg(options::OPT_o
)) {
2079 Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
);
2080 CmdArgs
.push_back("-auxbase-strip");
2081 CmdArgs
.push_back(OutputOpt
->getValue(Args
));
2083 CmdArgs
.push_back("-auxbase");
2084 CmdArgs
.push_back(darwin::CC1::getBaseInputStem(Args
, Inputs
));
2087 Args
.AddAllArgs(CmdArgs
, options::OPT_g_Group
);
2089 Args
.AddAllArgs(CmdArgs
, options::OPT_O
);
2090 // FIXME: -Wall is getting some special treatment. Investigate.
2091 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
, options::OPT_pedantic_Group
);
2092 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2093 Args
.AddAllArgs(CmdArgs
, options::OPT_std_EQ
, options::OPT_ansi
,
2094 options::OPT_trigraphs
);
2095 if (!Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
2096 // Honor -std-default.
2097 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
2098 "-std=", /*Joined=*/true);
2101 if (Args
.hasArg(options::OPT_v
))
2102 CmdArgs
.push_back("-version");
2103 if (Args
.hasArg(options::OPT_pg
))
2104 CmdArgs
.push_back("-p");
2105 Args
.AddLastArg(CmdArgs
, options::OPT_p
);
2107 // The driver treats -fsyntax-only specially.
2108 if (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
2109 getToolChain().getTriple().getArch() == llvm::Triple::thumb
) {
2110 // Removes -fbuiltin-str{cat,cpy}; these aren't recognized by cc1 but are
2111 // used to inhibit the default -fno-builtin-str{cat,cpy}.
2113 // FIXME: Should we grow a better way to deal with "removing" args?
2114 for (arg_iterator it
= Args
.filtered_begin(options::OPT_f_Group
,
2115 options::OPT_fsyntax_only
),
2116 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
2117 if (!(*it
)->getOption().matches(options::OPT_fbuiltin_strcat
) &&
2118 !(*it
)->getOption().matches(options::OPT_fbuiltin_strcpy
)) {
2120 (*it
)->render(Args
, CmdArgs
);
2124 Args
.AddAllArgs(CmdArgs
, options::OPT_f_Group
, options::OPT_fsyntax_only
);
2126 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
2127 if (Args
.hasArg(options::OPT_Qn
))
2128 CmdArgs
.push_back("-fno-ident");
2130 // FIXME: This isn't correct.
2131 //Args.AddLastArg(CmdArgs, options::OPT__help)
2132 //Args.AddLastArg(CmdArgs, options::OPT__targetHelp)
2134 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2136 // FIXME: Still don't get what is happening here. Investigate.
2137 Args
.AddAllArgs(CmdArgs
, options::OPT__param
);
2139 if (Args
.hasArg(options::OPT_fmudflap
) ||
2140 Args
.hasArg(options::OPT_fmudflapth
)) {
2141 CmdArgs
.push_back("-fno-builtin");
2142 CmdArgs
.push_back("-fno-merge-constants");
2145 if (Args
.hasArg(options::OPT_coverage
)) {
2146 CmdArgs
.push_back("-fprofile-arcs");
2147 CmdArgs
.push_back("-ftest-coverage");
2150 if (types::isCXX(Inputs
[0].getType()))
2151 CmdArgs
.push_back("-D__private_extern__=extern");
2154 void darwin::CC1::AddCPPOptionsArgs(const ArgList
&Args
, ArgStringList
&CmdArgs
,
2155 const InputInfoList
&Inputs
,
2156 const ArgStringList
&OutputArgs
) const {
2157 // Derived from cpp_options
2158 AddCPPUniqueOptionsArgs(Args
, CmdArgs
, Inputs
);
2160 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2162 AddCC1Args(Args
, CmdArgs
);
2164 // NOTE: The code below has some commonality with cpp_options, but
2165 // in classic gcc style ends up sending things in different
2166 // orders. This may be a good merge candidate once we drop pedantic
2169 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Group
);
2170 Args
.AddAllArgs(CmdArgs
, options::OPT_std_EQ
, options::OPT_ansi
,
2171 options::OPT_trigraphs
);
2172 if (!Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
2173 // Honor -std-default.
2174 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
2175 "-std=", /*Joined=*/true);
2177 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
, options::OPT_pedantic_Group
);
2178 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2180 // The driver treats -fsyntax-only specially.
2181 Args
.AddAllArgs(CmdArgs
, options::OPT_f_Group
, options::OPT_fsyntax_only
);
2183 if (Args
.hasArg(options::OPT_g_Group
) && !Args
.hasArg(options::OPT_g0
) &&
2184 !Args
.hasArg(options::OPT_fno_working_directory
))
2185 CmdArgs
.push_back("-fworking-directory");
2187 Args
.AddAllArgs(CmdArgs
, options::OPT_O
);
2188 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
2189 if (Args
.hasArg(options::OPT_save_temps
))
2190 CmdArgs
.push_back("-fpch-preprocess");
2193 void darwin::CC1::AddCPPUniqueOptionsArgs(const ArgList
&Args
,
2194 ArgStringList
&CmdArgs
,
2195 const InputInfoList
&Inputs
) const {
2196 const Driver
&D
= getToolChain().getDriver();
2198 CheckPreprocessingOptions(D
, Args
);
2200 // Derived from cpp_unique_options.
2201 // -{C,CC} only with -E is checked in CheckPreprocessingOptions().
2202 Args
.AddLastArg(CmdArgs
, options::OPT_C
);
2203 Args
.AddLastArg(CmdArgs
, options::OPT_CC
);
2204 if (!Args
.hasArg(options::OPT_Q
))
2205 CmdArgs
.push_back("-quiet");
2206 Args
.AddAllArgs(CmdArgs
, options::OPT_nostdinc
);
2207 Args
.AddAllArgs(CmdArgs
, options::OPT_nostdincxx
);
2208 Args
.AddLastArg(CmdArgs
, options::OPT_v
);
2209 Args
.AddAllArgs(CmdArgs
, options::OPT_I_Group
, options::OPT_F
);
2210 Args
.AddLastArg(CmdArgs
, options::OPT_P
);
2212 // FIXME: Handle %I properly.
2213 if (getToolChain().getArchName() == "x86_64") {
2214 CmdArgs
.push_back("-imultilib");
2215 CmdArgs
.push_back("x86_64");
2218 if (Args
.hasArg(options::OPT_MD
)) {
2219 CmdArgs
.push_back("-MD");
2220 CmdArgs
.push_back(darwin::CC1::getDependencyFileName(Args
, Inputs
));
2223 if (Args
.hasArg(options::OPT_MMD
)) {
2224 CmdArgs
.push_back("-MMD");
2225 CmdArgs
.push_back(darwin::CC1::getDependencyFileName(Args
, Inputs
));
2228 Args
.AddLastArg(CmdArgs
, options::OPT_M
);
2229 Args
.AddLastArg(CmdArgs
, options::OPT_MM
);
2230 Args
.AddAllArgs(CmdArgs
, options::OPT_MF
);
2231 Args
.AddLastArg(CmdArgs
, options::OPT_MG
);
2232 Args
.AddLastArg(CmdArgs
, options::OPT_MP
);
2233 Args
.AddAllArgs(CmdArgs
, options::OPT_MQ
);
2234 Args
.AddAllArgs(CmdArgs
, options::OPT_MT
);
2235 if (!Args
.hasArg(options::OPT_M
) && !Args
.hasArg(options::OPT_MM
) &&
2236 (Args
.hasArg(options::OPT_MD
) || Args
.hasArg(options::OPT_MMD
))) {
2237 if (Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
)) {
2238 CmdArgs
.push_back("-MQ");
2239 CmdArgs
.push_back(OutputOpt
->getValue(Args
));
2243 Args
.AddLastArg(CmdArgs
, options::OPT_remap
);
2244 if (Args
.hasArg(options::OPT_g3
))
2245 CmdArgs
.push_back("-dD");
2246 Args
.AddLastArg(CmdArgs
, options::OPT_H
);
2248 AddCPPArgs(Args
, CmdArgs
);
2250 Args
.AddAllArgs(CmdArgs
, options::OPT_D
, options::OPT_U
, options::OPT_A
);
2251 Args
.AddAllArgs(CmdArgs
, options::OPT_i_Group
);
2253 for (InputInfoList::const_iterator
2254 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2255 const InputInfo
&II
= *it
;
2257 CmdArgs
.push_back(II
.getFilename());
2260 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wp_COMMA
,
2261 options::OPT_Xpreprocessor
);
2263 if (Args
.hasArg(options::OPT_fmudflap
)) {
2264 CmdArgs
.push_back("-D_MUDFLAP");
2265 CmdArgs
.push_back("-include");
2266 CmdArgs
.push_back("mf-runtime.h");
2269 if (Args
.hasArg(options::OPT_fmudflapth
)) {
2270 CmdArgs
.push_back("-D_MUDFLAP");
2271 CmdArgs
.push_back("-D_MUDFLAPTH");
2272 CmdArgs
.push_back("-include");
2273 CmdArgs
.push_back("mf-runtime.h");
2277 void darwin::CC1::AddCPPArgs(const ArgList
&Args
,
2278 ArgStringList
&CmdArgs
) const {
2279 // Derived from cpp spec.
2281 if (Args
.hasArg(options::OPT_static
)) {
2282 // The gcc spec is broken here, it refers to dynamic but
2283 // that has been translated. Start by being bug compatible.
2285 // if (!Args.hasArg(arglist.parser.dynamicOption))
2286 CmdArgs
.push_back("-D__STATIC__");
2288 CmdArgs
.push_back("-D__DYNAMIC__");
2290 if (Args
.hasArg(options::OPT_pthread
))
2291 CmdArgs
.push_back("-D_REENTRANT");
2294 void darwin::Preprocess::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2295 const InputInfo
&Output
,
2296 const InputInfoList
&Inputs
,
2297 const ArgList
&Args
,
2298 const char *LinkingOutput
) const {
2299 ArgStringList CmdArgs
;
2301 assert(Inputs
.size() == 1 && "Unexpected number of inputs!");
2303 CmdArgs
.push_back("-E");
2305 if (Args
.hasArg(options::OPT_traditional
) ||
2306 Args
.hasArg(options::OPT_traditional_cpp
))
2307 CmdArgs
.push_back("-traditional-cpp");
2309 ArgStringList OutputArgs
;
2310 assert(Output
.isFilename() && "Unexpected CC1 output.");
2311 OutputArgs
.push_back("-o");
2312 OutputArgs
.push_back(Output
.getFilename());
2314 if (Args
.hasArg(options::OPT_E
)) {
2315 AddCPPOptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2317 AddCPPOptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2318 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2321 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Group
);
2323 const char *CC1Name
= getCC1Name(Inputs
[0].getType());
2325 Args
.MakeArgString(getToolChain().GetProgramPath(CC1Name
));
2326 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2329 void darwin::Compile::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2330 const InputInfo
&Output
,
2331 const InputInfoList
&Inputs
,
2332 const ArgList
&Args
,
2333 const char *LinkingOutput
) const {
2334 const Driver
&D
= getToolChain().getDriver();
2335 ArgStringList CmdArgs
;
2337 assert(Inputs
.size() == 1 && "Unexpected number of inputs!");
2339 types::ID InputType
= Inputs
[0].getType();
2341 if ((A
= Args
.getLastArg(options::OPT_traditional
)))
2342 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
2343 << A
->getAsString(Args
) << "-E";
2345 if (JA
.getType() == types::TY_LLVM_IR
||
2346 JA
.getType() == types::TY_LTO_IR
)
2347 CmdArgs
.push_back("-emit-llvm");
2348 else if (JA
.getType() == types::TY_LLVM_BC
||
2349 JA
.getType() == types::TY_LTO_BC
)
2350 CmdArgs
.push_back("-emit-llvm-bc");
2351 else if (Output
.getType() == types::TY_AST
)
2352 D
.Diag(clang::diag::err_drv_no_ast_support
)
2353 << getToolChain().getTripleString();
2354 else if (JA
.getType() != types::TY_PP_Asm
&&
2355 JA
.getType() != types::TY_PCH
)
2356 D
.Diag(clang::diag::err_drv_invalid_gcc_output_type
)
2357 << getTypeName(JA
.getType());
2359 ArgStringList OutputArgs
;
2360 if (Output
.getType() != types::TY_PCH
) {
2361 OutputArgs
.push_back("-o");
2362 if (Output
.isNothing())
2363 OutputArgs
.push_back("/dev/null");
2365 OutputArgs
.push_back(Output
.getFilename());
2368 // There is no need for this level of compatibility, but it makes
2370 bool OutputArgsEarly
= (Args
.hasArg(options::OPT_fsyntax_only
) ||
2371 Args
.hasArg(options::OPT_S
));
2373 if (types::getPreprocessedType(InputType
) != types::TY_INVALID
) {
2374 AddCPPUniqueOptionsArgs(Args
, CmdArgs
, Inputs
);
2375 if (OutputArgsEarly
) {
2376 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2378 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2379 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2382 CmdArgs
.push_back("-fpreprocessed");
2384 for (InputInfoList::const_iterator
2385 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2386 const InputInfo
&II
= *it
;
2388 // Reject AST inputs.
2389 if (II
.getType() == types::TY_AST
) {
2390 D
.Diag(clang::diag::err_drv_no_ast_support
)
2391 << getToolChain().getTripleString();
2395 CmdArgs
.push_back(II
.getFilename());
2398 if (OutputArgsEarly
) {
2399 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2401 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2402 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2406 if (Output
.getType() == types::TY_PCH
) {
2407 assert(Output
.isFilename() && "Invalid PCH output.");
2409 CmdArgs
.push_back("-o");
2410 // NOTE: gcc uses a temp .s file for this, but there doesn't seem
2411 // to be a good reason.
2412 CmdArgs
.push_back("/dev/null");
2414 CmdArgs
.push_back("--output-pch=");
2415 CmdArgs
.push_back(Output
.getFilename());
2418 const char *CC1Name
= getCC1Name(Inputs
[0].getType());
2420 Args
.MakeArgString(getToolChain().GetProgramPath(CC1Name
));
2421 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2424 void darwin::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2425 const InputInfo
&Output
,
2426 const InputInfoList
&Inputs
,
2427 const ArgList
&Args
,
2428 const char *LinkingOutput
) const {
2429 ArgStringList CmdArgs
;
2431 assert(Inputs
.size() == 1 && "Unexpected number of inputs.");
2432 const InputInfo
&Input
= Inputs
[0];
2434 // Bit of a hack, this is only used for original inputs.
2436 // FIXME: This is broken for preprocessed .s inputs.
2437 if (Input
.isFilename() &&
2438 strcmp(Input
.getFilename(), Input
.getBaseInput()) == 0) {
2439 if (Args
.hasArg(options::OPT_gstabs
))
2440 CmdArgs
.push_back("--gstabs");
2441 else if (Args
.hasArg(options::OPT_g_Group
))
2442 CmdArgs
.push_back("--gdwarf2");
2445 // Derived from asm spec.
2446 AddDarwinArch(Args
, CmdArgs
);
2448 // Use -force_cpusubtype_ALL on x86 by default.
2449 if (getToolChain().getTriple().getArch() == llvm::Triple::x86
||
2450 getToolChain().getTriple().getArch() == llvm::Triple::x86_64
||
2451 Args
.hasArg(options::OPT_force__cpusubtype__ALL
))
2452 CmdArgs
.push_back("-force_cpusubtype_ALL");
2454 if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64
&&
2455 (Args
.hasArg(options::OPT_mkernel
) ||
2456 Args
.hasArg(options::OPT_static
) ||
2457 Args
.hasArg(options::OPT_fapple_kext
)))
2458 CmdArgs
.push_back("-static");
2460 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2461 options::OPT_Xassembler
);
2463 assert(Output
.isFilename() && "Unexpected lipo output.");
2464 CmdArgs
.push_back("-o");
2465 CmdArgs
.push_back(Output
.getFilename());
2467 assert(Input
.isFilename() && "Invalid input.");
2468 CmdArgs
.push_back(Input
.getFilename());
2470 // asm_final spec is empty.
2473 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
2474 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2477 void darwin::DarwinTool::AddDarwinArch(const ArgList
&Args
,
2478 ArgStringList
&CmdArgs
) const {
2479 llvm::StringRef ArchName
= getDarwinToolChain().getDarwinArchName(Args
);
2481 // Derived from darwin_arch spec.
2482 CmdArgs
.push_back("-arch");
2483 CmdArgs
.push_back(Args
.MakeArgString(ArchName
));
2485 // FIXME: Is this needed anymore?
2486 if (ArchName
== "arm")
2487 CmdArgs
.push_back("-force_cpusubtype_ALL");
2490 void darwin::Link::AddLinkArgs(Compilation
&C
,
2491 const ArgList
&Args
,
2492 ArgStringList
&CmdArgs
) const {
2493 const Driver
&D
= getToolChain().getDriver();
2495 unsigned Version
[3] = { 0, 0, 0 };
2496 if (Arg
*A
= Args
.getLastArg(options::OPT_mlinker_version_EQ
)) {
2498 if (!Driver::GetReleaseVersion(A
->getValue(Args
), Version
[0],
2499 Version
[1], Version
[2], HadExtra
) ||
2501 D
.Diag(clang::diag::err_drv_invalid_version_number
)
2502 << A
->getAsString(Args
);
2505 // Newer linkers support -demangle, pass it if supported and not disabled by
2508 // FIXME: We temporarily avoid passing -demangle to any iOS linker, because
2509 // unfortunately we can't be guaranteed that the linker version used there
2510 // will match the linker version detected at configure time. We need the
2511 // universal driver.
2512 if (Version
[0] >= 100 && !Args
.hasArg(options::OPT_Z_Xlinker__no_demangle
) &&
2513 !getDarwinToolChain().isTargetIPhoneOS()) {
2514 // Don't pass -demangle to ld_classic.
2516 // FIXME: This is a temporary workaround, ld should be handling this.
2517 bool UsesLdClassic
= (getToolChain().getArch() == llvm::Triple::x86
&&
2518 Args
.hasArg(options::OPT_static
));
2519 if (getToolChain().getArch() == llvm::Triple::x86
) {
2520 for (arg_iterator it
= Args
.filtered_begin(options::OPT_Xlinker
,
2521 options::OPT_Wl_COMMA
),
2522 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
2524 for (unsigned i
= 0, e
= A
->getNumValues(); i
!= e
; ++i
)
2525 if (llvm::StringRef(A
->getValue(Args
, i
)) == "-kext")
2526 UsesLdClassic
= true;
2530 CmdArgs
.push_back("-demangle");
2533 // Derived from the "link" spec.
2534 Args
.AddAllArgs(CmdArgs
, options::OPT_static
);
2535 if (!Args
.hasArg(options::OPT_static
))
2536 CmdArgs
.push_back("-dynamic");
2537 if (Args
.hasArg(options::OPT_fgnu_runtime
)) {
2538 // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu
2539 // here. How do we wish to handle such things?
2542 if (!Args
.hasArg(options::OPT_dynamiclib
)) {
2543 AddDarwinArch(Args
, CmdArgs
);
2544 // FIXME: Why do this only on this path?
2545 Args
.AddLastArg(CmdArgs
, options::OPT_force__cpusubtype__ALL
);
2547 Args
.AddLastArg(CmdArgs
, options::OPT_bundle
);
2548 Args
.AddAllArgs(CmdArgs
, options::OPT_bundle__loader
);
2549 Args
.AddAllArgs(CmdArgs
, options::OPT_client__name
);
2552 if ((A
= Args
.getLastArg(options::OPT_compatibility__version
)) ||
2553 (A
= Args
.getLastArg(options::OPT_current__version
)) ||
2554 (A
= Args
.getLastArg(options::OPT_install__name
)))
2555 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
2556 << A
->getAsString(Args
) << "-dynamiclib";
2558 Args
.AddLastArg(CmdArgs
, options::OPT_force__flat__namespace
);
2559 Args
.AddLastArg(CmdArgs
, options::OPT_keep__private__externs
);
2560 Args
.AddLastArg(CmdArgs
, options::OPT_private__bundle
);
2562 CmdArgs
.push_back("-dylib");
2565 if ((A
= Args
.getLastArg(options::OPT_bundle
)) ||
2566 (A
= Args
.getLastArg(options::OPT_bundle__loader
)) ||
2567 (A
= Args
.getLastArg(options::OPT_client__name
)) ||
2568 (A
= Args
.getLastArg(options::OPT_force__flat__namespace
)) ||
2569 (A
= Args
.getLastArg(options::OPT_keep__private__externs
)) ||
2570 (A
= Args
.getLastArg(options::OPT_private__bundle
)))
2571 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
2572 << A
->getAsString(Args
) << "-dynamiclib";
2574 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_compatibility__version
,
2575 "-dylib_compatibility_version");
2576 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_current__version
,
2577 "-dylib_current_version");
2579 AddDarwinArch(Args
, CmdArgs
);
2581 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_install__name
,
2582 "-dylib_install_name");
2585 Args
.AddLastArg(CmdArgs
, options::OPT_all__load
);
2586 Args
.AddAllArgs(CmdArgs
, options::OPT_allowable__client
);
2587 Args
.AddLastArg(CmdArgs
, options::OPT_bind__at__load
);
2588 if (getDarwinToolChain().isTargetIPhoneOS())
2589 Args
.AddLastArg(CmdArgs
, options::OPT_arch__errors__fatal
);
2590 Args
.AddLastArg(CmdArgs
, options::OPT_dead__strip
);
2591 Args
.AddLastArg(CmdArgs
, options::OPT_no__dead__strip__inits__and__terms
);
2592 Args
.AddAllArgs(CmdArgs
, options::OPT_dylib__file
);
2593 Args
.AddLastArg(CmdArgs
, options::OPT_dynamic
);
2594 Args
.AddAllArgs(CmdArgs
, options::OPT_exported__symbols__list
);
2595 Args
.AddLastArg(CmdArgs
, options::OPT_flat__namespace
);
2596 Args
.AddAllArgs(CmdArgs
, options::OPT_headerpad__max__install__names
);
2597 Args
.AddAllArgs(CmdArgs
, options::OPT_image__base
);
2598 Args
.AddAllArgs(CmdArgs
, options::OPT_init
);
2600 // Adding all arguments doesn't make sense here but this is what gcc does. One
2601 // of this should always be present thanks to argument translation.
2602 assert((Args
.hasArg(options::OPT_mmacosx_version_min_EQ
) ||
2603 Args
.hasArg(options::OPT_miphoneos_version_min_EQ
)) &&
2604 "Missing version argument (lost in translation)?");
2605 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_mmacosx_version_min_EQ
,
2606 "-macosx_version_min");
2607 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_miphoneos_version_min_EQ
,
2608 "-iphoneos_version_min");
2609 Args
.AddLastArg(CmdArgs
, options::OPT_nomultidefs
);
2610 Args
.AddLastArg(CmdArgs
, options::OPT_multi__module
);
2611 Args
.AddLastArg(CmdArgs
, options::OPT_single__module
);
2612 Args
.AddAllArgs(CmdArgs
, options::OPT_multiply__defined
);
2613 Args
.AddAllArgs(CmdArgs
, options::OPT_multiply__defined__unused
);
2615 if (const Arg
*A
= Args
.getLastArg(options::OPT_fpie
, options::OPT_fPIE
,
2616 options::OPT_fno_pie
,
2617 options::OPT_fno_PIE
)) {
2618 if (A
->getOption().matches(options::OPT_fpie
) ||
2619 A
->getOption().matches(options::OPT_fPIE
))
2620 CmdArgs
.push_back("-pie");
2622 CmdArgs
.push_back("-no_pie");
2625 Args
.AddLastArg(CmdArgs
, options::OPT_prebind
);
2626 Args
.AddLastArg(CmdArgs
, options::OPT_noprebind
);
2627 Args
.AddLastArg(CmdArgs
, options::OPT_nofixprebinding
);
2628 Args
.AddLastArg(CmdArgs
, options::OPT_prebind__all__twolevel__modules
);
2629 Args
.AddLastArg(CmdArgs
, options::OPT_read__only__relocs
);
2630 Args
.AddAllArgs(CmdArgs
, options::OPT_sectcreate
);
2631 Args
.AddAllArgs(CmdArgs
, options::OPT_sectorder
);
2632 Args
.AddAllArgs(CmdArgs
, options::OPT_seg1addr
);
2633 Args
.AddAllArgs(CmdArgs
, options::OPT_segprot
);
2634 Args
.AddAllArgs(CmdArgs
, options::OPT_segaddr
);
2635 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__only__addr
);
2636 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__write__addr
);
2637 Args
.AddAllArgs(CmdArgs
, options::OPT_seg__addr__table
);
2638 Args
.AddAllArgs(CmdArgs
, options::OPT_seg__addr__table__filename
);
2639 Args
.AddAllArgs(CmdArgs
, options::OPT_sub__library
);
2640 Args
.AddAllArgs(CmdArgs
, options::OPT_sub__umbrella
);
2642 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_isysroot
, "-syslibroot");
2643 if (getDarwinToolChain().isTargetIPhoneOS()) {
2644 if (!Args
.hasArg(options::OPT_isysroot
)) {
2645 CmdArgs
.push_back("-syslibroot");
2646 CmdArgs
.push_back("/Developer/SDKs/Extra");
2650 Args
.AddLastArg(CmdArgs
, options::OPT_twolevel__namespace
);
2651 Args
.AddLastArg(CmdArgs
, options::OPT_twolevel__namespace__hints
);
2652 Args
.AddAllArgs(CmdArgs
, options::OPT_umbrella
);
2653 Args
.AddAllArgs(CmdArgs
, options::OPT_undefined
);
2654 Args
.AddAllArgs(CmdArgs
, options::OPT_unexported__symbols__list
);
2655 Args
.AddAllArgs(CmdArgs
, options::OPT_weak__reference__mismatches
);
2656 Args
.AddLastArg(CmdArgs
, options::OPT_X_Flag
);
2657 Args
.AddAllArgs(CmdArgs
, options::OPT_y
);
2658 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2659 Args
.AddAllArgs(CmdArgs
, options::OPT_pagezero__size
);
2660 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__
);
2661 Args
.AddLastArg(CmdArgs
, options::OPT_seglinkedit
);
2662 Args
.AddLastArg(CmdArgs
, options::OPT_noseglinkedit
);
2663 Args
.AddAllArgs(CmdArgs
, options::OPT_sectalign
);
2664 Args
.AddAllArgs(CmdArgs
, options::OPT_sectobjectsymbols
);
2665 Args
.AddAllArgs(CmdArgs
, options::OPT_segcreate
);
2666 Args
.AddLastArg(CmdArgs
, options::OPT_whyload
);
2667 Args
.AddLastArg(CmdArgs
, options::OPT_whatsloaded
);
2668 Args
.AddAllArgs(CmdArgs
, options::OPT_dylinker__install__name
);
2669 Args
.AddLastArg(CmdArgs
, options::OPT_dylinker
);
2670 Args
.AddLastArg(CmdArgs
, options::OPT_Mach
);
2673 void darwin::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2674 const InputInfo
&Output
,
2675 const InputInfoList
&Inputs
,
2676 const ArgList
&Args
,
2677 const char *LinkingOutput
) const {
2678 assert(Output
.getType() == types::TY_Image
&& "Invalid linker output type.");
2680 // The logic here is derived from gcc's behavior; most of which
2681 // comes from specs (starting with link_command). Consult gcc for
2682 // more information.
2683 ArgStringList CmdArgs
;
2685 // I'm not sure why this particular decomposition exists in gcc, but
2686 // we follow suite for ease of comparison.
2687 AddLinkArgs(C
, Args
, CmdArgs
);
2689 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Flag
);
2690 Args
.AddAllArgs(CmdArgs
, options::OPT_s
);
2691 Args
.AddAllArgs(CmdArgs
, options::OPT_t
);
2692 Args
.AddAllArgs(CmdArgs
, options::OPT_Z_Flag
);
2693 Args
.AddAllArgs(CmdArgs
, options::OPT_u_Group
);
2694 Args
.AddAllArgs(CmdArgs
, options::OPT_A
);
2695 Args
.AddLastArg(CmdArgs
, options::OPT_e
);
2696 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Separate
);
2697 Args
.AddAllArgs(CmdArgs
, options::OPT_r
);
2699 // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading
2700 // members of static archive libraries which implement Objective-C classes or
2702 if (Args
.hasArg(options::OPT_ObjC
) || Args
.hasArg(options::OPT_ObjCXX
))
2703 CmdArgs
.push_back("-ObjC");
2705 CmdArgs
.push_back("-o");
2706 CmdArgs
.push_back(Output
.getFilename());
2708 if (!Args
.hasArg(options::OPT_A
) &&
2709 !Args
.hasArg(options::OPT_nostdlib
) &&
2710 !Args
.hasArg(options::OPT_nostartfiles
)) {
2711 // Derived from startfile spec.
2712 if (Args
.hasArg(options::OPT_dynamiclib
)) {
2713 // Derived from darwin_dylib1 spec.
2714 if (getDarwinToolChain().isTargetIPhoneOS()) {
2715 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2716 CmdArgs
.push_back("-ldylib1.o");
2718 if (getDarwinToolChain().isMacosxVersionLT(10, 5))
2719 CmdArgs
.push_back("-ldylib1.o");
2720 else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2721 CmdArgs
.push_back("-ldylib1.10.5.o");
2724 if (Args
.hasArg(options::OPT_bundle
)) {
2725 if (!Args
.hasArg(options::OPT_static
)) {
2726 // Derived from darwin_bundle1 spec.
2727 if (getDarwinToolChain().isTargetIPhoneOS()) {
2728 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2729 CmdArgs
.push_back("-lbundle1.o");
2731 if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2732 CmdArgs
.push_back("-lbundle1.o");
2736 if (Args
.hasArg(options::OPT_pg
)) {
2737 if (Args
.hasArg(options::OPT_static
) ||
2738 Args
.hasArg(options::OPT_object
) ||
2739 Args
.hasArg(options::OPT_preload
)) {
2740 CmdArgs
.push_back("-lgcrt0.o");
2742 CmdArgs
.push_back("-lgcrt1.o");
2744 // darwin_crt2 spec is empty.
2747 if (Args
.hasArg(options::OPT_static
) ||
2748 Args
.hasArg(options::OPT_object
) ||
2749 Args
.hasArg(options::OPT_preload
)) {
2750 CmdArgs
.push_back("-lcrt0.o");
2752 // Derived from darwin_crt1 spec.
2753 if (getDarwinToolChain().isTargetIPhoneOS()) {
2754 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2755 CmdArgs
.push_back("-lcrt1.o");
2757 CmdArgs
.push_back("-lcrt1.3.1.o");
2759 if (getDarwinToolChain().isMacosxVersionLT(10, 5))
2760 CmdArgs
.push_back("-lcrt1.o");
2761 else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2762 CmdArgs
.push_back("-lcrt1.10.5.o");
2764 CmdArgs
.push_back("-lcrt1.10.6.o");
2766 // darwin_crt2 spec is empty.
2773 if (!getDarwinToolChain().isTargetIPhoneOS() &&
2774 Args
.hasArg(options::OPT_shared_libgcc
) &&
2775 getDarwinToolChain().isMacosxVersionLT(10, 5)) {
2777 Args
.MakeArgString(getToolChain().GetFilePath("crt3.o"));
2778 CmdArgs
.push_back(Str
);
2782 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
2784 if (Args
.hasArg(options::OPT_fopenmp
))
2785 // This is more complicated in gcc...
2786 CmdArgs
.push_back("-lgomp");
2788 getDarwinToolChain().AddLinkSearchPathArgs(Args
, CmdArgs
);
2790 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
2792 if (LinkingOutput
) {
2793 CmdArgs
.push_back("-arch_multiple");
2794 CmdArgs
.push_back("-final_output");
2795 CmdArgs
.push_back(LinkingOutput
);
2798 if (Args
.hasArg(options::OPT_fprofile_arcs
) ||
2799 Args
.hasArg(options::OPT_fprofile_generate
) ||
2800 Args
.hasArg(options::OPT_fcreate_profile
) ||
2801 Args
.hasArg(options::OPT_coverage
))
2802 CmdArgs
.push_back("-lgcov");
2804 if (Args
.hasArg(options::OPT_fnested_functions
))
2805 CmdArgs
.push_back("-allow_stack_execute");
2807 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2808 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
2809 if (getToolChain().getDriver().CCCIsCXX
)
2810 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
2812 // link_ssp spec is empty.
2814 // Let the tool chain choose which runtime library to link.
2815 getDarwinToolChain().AddLinkRuntimeLibArgs(Args
, CmdArgs
);
2818 if (!Args
.hasArg(options::OPT_A
) &&
2819 !Args
.hasArg(options::OPT_nostdlib
) &&
2820 !Args
.hasArg(options::OPT_nostartfiles
)) {
2821 // endfile_spec is empty.
2824 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
2825 Args
.AddAllArgs(CmdArgs
, options::OPT_F
);
2828 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
2829 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2832 void darwin::Lipo::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2833 const InputInfo
&Output
,
2834 const InputInfoList
&Inputs
,
2835 const ArgList
&Args
,
2836 const char *LinkingOutput
) const {
2837 ArgStringList CmdArgs
;
2839 CmdArgs
.push_back("-create");
2840 assert(Output
.isFilename() && "Unexpected lipo output.");
2842 CmdArgs
.push_back("-output");
2843 CmdArgs
.push_back(Output
.getFilename());
2845 for (InputInfoList::const_iterator
2846 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2847 const InputInfo
&II
= *it
;
2848 assert(II
.isFilename() && "Unexpected lipo input.");
2849 CmdArgs
.push_back(II
.getFilename());
2852 Args
.MakeArgString(getToolChain().GetProgramPath("lipo"));
2853 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2856 void darwin::Dsymutil::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2857 const InputInfo
&Output
,
2858 const InputInfoList
&Inputs
,
2859 const ArgList
&Args
,
2860 const char *LinkingOutput
) const {
2861 ArgStringList CmdArgs
;
2863 assert(Inputs
.size() == 1 && "Unable to handle multiple inputs.");
2864 const InputInfo
&Input
= Inputs
[0];
2865 assert(Input
.isFilename() && "Unexpected dsymutil input.");
2866 CmdArgs
.push_back(Input
.getFilename());
2868 CmdArgs
.push_back("-o");
2869 CmdArgs
.push_back(Output
.getFilename());
2872 Args
.MakeArgString(getToolChain().GetProgramPath("dsymutil"));
2873 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2876 void auroraux::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2877 const InputInfo
&Output
,
2878 const InputInfoList
&Inputs
,
2879 const ArgList
&Args
,
2880 const char *LinkingOutput
) const {
2881 ArgStringList CmdArgs
;
2883 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2884 options::OPT_Xassembler
);
2886 CmdArgs
.push_back("-o");
2887 CmdArgs
.push_back(Output
.getFilename());
2889 for (InputInfoList::const_iterator
2890 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2891 const InputInfo
&II
= *it
;
2892 CmdArgs
.push_back(II
.getFilename());
2896 Args
.MakeArgString(getToolChain().GetProgramPath("gas"));
2897 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2900 void auroraux::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2901 const InputInfo
&Output
,
2902 const InputInfoList
&Inputs
,
2903 const ArgList
&Args
,
2904 const char *LinkingOutput
) const {
2905 ArgStringList CmdArgs
;
2907 if ((!Args
.hasArg(options::OPT_nostdlib
)) &&
2908 (!Args
.hasArg(options::OPT_shared
))) {
2909 CmdArgs
.push_back("-e");
2910 CmdArgs
.push_back("_start");
2913 if (Args
.hasArg(options::OPT_static
)) {
2914 CmdArgs
.push_back("-Bstatic");
2915 CmdArgs
.push_back("-dn");
2917 // CmdArgs.push_back("--eh-frame-hdr");
2918 CmdArgs
.push_back("-Bdynamic");
2919 if (Args
.hasArg(options::OPT_shared
)) {
2920 CmdArgs
.push_back("-shared");
2922 CmdArgs
.push_back("--dynamic-linker");
2923 CmdArgs
.push_back("/lib/ld.so.1"); // 64Bit Path /lib/amd64/ld.so.1
2927 if (Output
.isFilename()) {
2928 CmdArgs
.push_back("-o");
2929 CmdArgs
.push_back(Output
.getFilename());
2931 assert(Output
.isNothing() && "Invalid output.");
2934 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2935 !Args
.hasArg(options::OPT_nostartfiles
)) {
2936 if (!Args
.hasArg(options::OPT_shared
)) {
2937 CmdArgs
.push_back(Args
.MakeArgString(
2938 getToolChain().GetFilePath("crt1.o")));
2939 CmdArgs
.push_back(Args
.MakeArgString(
2940 getToolChain().GetFilePath("crti.o")));
2941 CmdArgs
.push_back(Args
.MakeArgString(
2942 getToolChain().GetFilePath("crtbegin.o")));
2944 CmdArgs
.push_back(Args
.MakeArgString(
2945 getToolChain().GetFilePath("crti.o")));
2947 CmdArgs
.push_back(Args
.MakeArgString(
2948 getToolChain().GetFilePath("crtn.o")));
2951 CmdArgs
.push_back(Args
.MakeArgString("-L/opt/gcc4/lib/gcc/"
2952 + getToolChain().getTripleString()
2955 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
2956 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
2957 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
2959 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
2961 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2962 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
2963 // FIXME: For some reason GCC passes -lgcc before adding
2964 // the default system libraries. Just mimic this for now.
2965 CmdArgs
.push_back("-lgcc");
2967 if (Args
.hasArg(options::OPT_pthread
))
2968 CmdArgs
.push_back("-pthread");
2969 if (!Args
.hasArg(options::OPT_shared
))
2970 CmdArgs
.push_back("-lc");
2971 CmdArgs
.push_back("-lgcc");
2974 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2975 !Args
.hasArg(options::OPT_nostartfiles
)) {
2976 if (!Args
.hasArg(options::OPT_shared
))
2977 CmdArgs
.push_back(Args
.MakeArgString(
2978 getToolChain().GetFilePath("crtend.o")));
2982 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
2983 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2986 void openbsd::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2987 const InputInfo
&Output
,
2988 const InputInfoList
&Inputs
,
2989 const ArgList
&Args
,
2990 const char *LinkingOutput
) const {
2991 ArgStringList CmdArgs
;
2993 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2994 options::OPT_Xassembler
);
2996 CmdArgs
.push_back("-o");
2997 CmdArgs
.push_back(Output
.getFilename());
2999 for (InputInfoList::const_iterator
3000 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3001 const InputInfo
&II
= *it
;
3002 CmdArgs
.push_back(II
.getFilename());
3006 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3007 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3010 void openbsd::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3011 const InputInfo
&Output
,
3012 const InputInfoList
&Inputs
,
3013 const ArgList
&Args
,
3014 const char *LinkingOutput
) const {
3015 const Driver
&D
= getToolChain().getDriver();
3016 ArgStringList CmdArgs
;
3018 if ((!Args
.hasArg(options::OPT_nostdlib
)) &&
3019 (!Args
.hasArg(options::OPT_shared
))) {
3020 CmdArgs
.push_back("-e");
3021 CmdArgs
.push_back("__start");
3024 if (Args
.hasArg(options::OPT_static
)) {
3025 CmdArgs
.push_back("-Bstatic");
3027 if (Args
.hasArg(options::OPT_rdynamic
))
3028 CmdArgs
.push_back("-export-dynamic");
3029 CmdArgs
.push_back("--eh-frame-hdr");
3030 CmdArgs
.push_back("-Bdynamic");
3031 if (Args
.hasArg(options::OPT_shared
)) {
3032 CmdArgs
.push_back("-shared");
3034 CmdArgs
.push_back("-dynamic-linker");
3035 CmdArgs
.push_back("/usr/libexec/ld.so");
3039 if (Output
.isFilename()) {
3040 CmdArgs
.push_back("-o");
3041 CmdArgs
.push_back(Output
.getFilename());
3043 assert(Output
.isNothing() && "Invalid output.");
3046 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3047 !Args
.hasArg(options::OPT_nostartfiles
)) {
3048 if (!Args
.hasArg(options::OPT_shared
)) {
3049 CmdArgs
.push_back(Args
.MakeArgString(
3050 getToolChain().GetFilePath("crt0.o")));
3051 CmdArgs
.push_back(Args
.MakeArgString(
3052 getToolChain().GetFilePath("crtbegin.o")));
3054 CmdArgs
.push_back(Args
.MakeArgString(
3055 getToolChain().GetFilePath("crtbeginS.o")));
3059 std::string Triple
= getToolChain().getTripleString();
3060 if (Triple
.substr(0, 6) == "x86_64")
3061 Triple
.replace(0, 6, "amd64");
3062 CmdArgs
.push_back(Args
.MakeArgString("-L/usr/lib/gcc-lib/" + Triple
+
3065 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3066 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3067 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3069 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3071 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3072 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3074 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3075 CmdArgs
.push_back("-lm");
3078 // FIXME: For some reason GCC passes -lgcc before adding
3079 // the default system libraries. Just mimic this for now.
3080 CmdArgs
.push_back("-lgcc");
3082 if (Args
.hasArg(options::OPT_pthread
))
3083 CmdArgs
.push_back("-pthread");
3084 if (!Args
.hasArg(options::OPT_shared
))
3085 CmdArgs
.push_back("-lc");
3086 CmdArgs
.push_back("-lgcc");
3089 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3090 !Args
.hasArg(options::OPT_nostartfiles
)) {
3091 if (!Args
.hasArg(options::OPT_shared
))
3092 CmdArgs
.push_back(Args
.MakeArgString(
3093 getToolChain().GetFilePath("crtend.o")));
3095 CmdArgs
.push_back(Args
.MakeArgString(
3096 getToolChain().GetFilePath("crtendS.o")));
3100 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3101 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3104 void freebsd::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3105 const InputInfo
&Output
,
3106 const InputInfoList
&Inputs
,
3107 const ArgList
&Args
,
3108 const char *LinkingOutput
) const {
3109 ArgStringList CmdArgs
;
3111 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
3112 // instruct as in the base system to assemble 32-bit code.
3113 if (getToolChain().getArchName() == "i386")
3114 CmdArgs
.push_back("--32");
3117 // Set byte order explicitly
3118 if (getToolChain().getArchName() == "mips")
3119 CmdArgs
.push_back("-EB");
3120 else if (getToolChain().getArchName() == "mipsel")
3121 CmdArgs
.push_back("-EL");
3123 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3124 options::OPT_Xassembler
);
3126 CmdArgs
.push_back("-o");
3127 CmdArgs
.push_back(Output
.getFilename());
3129 for (InputInfoList::const_iterator
3130 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3131 const InputInfo
&II
= *it
;
3132 CmdArgs
.push_back(II
.getFilename());
3136 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3137 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3140 void freebsd::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3141 const InputInfo
&Output
,
3142 const InputInfoList
&Inputs
,
3143 const ArgList
&Args
,
3144 const char *LinkingOutput
) const {
3145 const Driver
&D
= getToolChain().getDriver();
3146 ArgStringList CmdArgs
;
3148 if (Args
.hasArg(options::OPT_static
)) {
3149 CmdArgs
.push_back("-Bstatic");
3151 if (Args
.hasArg(options::OPT_rdynamic
))
3152 CmdArgs
.push_back("-export-dynamic");
3153 CmdArgs
.push_back("--eh-frame-hdr");
3154 if (Args
.hasArg(options::OPT_shared
)) {
3155 CmdArgs
.push_back("-Bshareable");
3157 CmdArgs
.push_back("-dynamic-linker");
3158 CmdArgs
.push_back("/libexec/ld-elf.so.1");
3162 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
3163 // instruct ld in the base system to link 32-bit code.
3164 if (getToolChain().getArchName() == "i386") {
3165 CmdArgs
.push_back("-m");
3166 CmdArgs
.push_back("elf_i386_fbsd");
3169 if (Output
.isFilename()) {
3170 CmdArgs
.push_back("-o");
3171 CmdArgs
.push_back(Output
.getFilename());
3173 assert(Output
.isNothing() && "Invalid output.");
3176 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3177 !Args
.hasArg(options::OPT_nostartfiles
)) {
3178 if (!Args
.hasArg(options::OPT_shared
)) {
3179 CmdArgs
.push_back(Args
.MakeArgString(
3180 getToolChain().GetFilePath("crt1.o")));
3181 CmdArgs
.push_back(Args
.MakeArgString(
3182 getToolChain().GetFilePath("crti.o")));
3183 CmdArgs
.push_back(Args
.MakeArgString(
3184 getToolChain().GetFilePath("crtbegin.o")));
3186 CmdArgs
.push_back(Args
.MakeArgString(
3187 getToolChain().GetFilePath("crti.o")));
3188 CmdArgs
.push_back(Args
.MakeArgString(
3189 getToolChain().GetFilePath("crtbeginS.o")));
3193 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3194 CmdArgs
.push_back("-L/usr/lib");
3195 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3196 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3197 Args
.AddAllArgs(CmdArgs
, options::OPT_s
);
3198 Args
.AddAllArgs(CmdArgs
, options::OPT_t
);
3199 Args
.AddAllArgs(CmdArgs
, options::OPT_Z_Flag
);
3200 Args
.AddAllArgs(CmdArgs
, options::OPT_r
);
3202 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3204 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3205 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3207 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3208 CmdArgs
.push_back("-lm");
3210 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
3211 // the default system libraries. Just mimic this for now.
3212 CmdArgs
.push_back("-lgcc");
3213 if (Args
.hasArg(options::OPT_static
)) {
3214 CmdArgs
.push_back("-lgcc_eh");
3216 CmdArgs
.push_back("--as-needed");
3217 CmdArgs
.push_back("-lgcc_s");
3218 CmdArgs
.push_back("--no-as-needed");
3221 if (Args
.hasArg(options::OPT_pthread
))
3222 CmdArgs
.push_back("-lpthread");
3223 CmdArgs
.push_back("-lc");
3225 CmdArgs
.push_back("-lgcc");
3226 if (Args
.hasArg(options::OPT_static
)) {
3227 CmdArgs
.push_back("-lgcc_eh");
3229 CmdArgs
.push_back("--as-needed");
3230 CmdArgs
.push_back("-lgcc_s");
3231 CmdArgs
.push_back("--no-as-needed");
3235 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3236 !Args
.hasArg(options::OPT_nostartfiles
)) {
3237 if (!Args
.hasArg(options::OPT_shared
))
3238 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3241 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3243 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3248 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3249 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3252 void netbsd::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3253 const InputInfo
&Output
,
3254 const InputInfoList
&Inputs
,
3255 const ArgList
&Args
,
3256 const char *LinkingOutput
) const {
3257 ArgStringList CmdArgs
;
3259 // When building 32-bit code on NetBSD/amd64, we have to explicitly
3260 // instruct as in the base system to assemble 32-bit code.
3261 if (getToolChain().getArchName() == "i386")
3262 CmdArgs
.push_back("--32");
3265 // Set byte order explicitly
3266 if (getToolChain().getArchName() == "mips")
3267 CmdArgs
.push_back("-EB");
3268 else if (getToolChain().getArchName() == "mipsel")
3269 CmdArgs
.push_back("-EL");
3271 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3272 options::OPT_Xassembler
);
3274 CmdArgs
.push_back("-o");
3275 CmdArgs
.push_back(Output
.getFilename());
3277 for (InputInfoList::const_iterator
3278 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3279 const InputInfo
&II
= *it
;
3280 CmdArgs
.push_back(II
.getFilename());
3284 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3285 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3288 void netbsd::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3289 const InputInfo
&Output
,
3290 const InputInfoList
&Inputs
,
3291 const ArgList
&Args
,
3292 const char *LinkingOutput
) const {
3293 const Driver
&D
= getToolChain().getDriver();
3294 ArgStringList CmdArgs
;
3296 if (Args
.hasArg(options::OPT_static
)) {
3297 CmdArgs
.push_back("-Bstatic");
3299 if (Args
.hasArg(options::OPT_rdynamic
))
3300 CmdArgs
.push_back("-export-dynamic");
3301 CmdArgs
.push_back("--eh-frame-hdr");
3302 if (Args
.hasArg(options::OPT_shared
)) {
3303 CmdArgs
.push_back("-Bshareable");
3305 CmdArgs
.push_back("-dynamic-linker");
3306 CmdArgs
.push_back("/libexec/ld.elf_so");
3310 // When building 32-bit code on NetBSD/amd64, we have to explicitly
3311 // instruct ld in the base system to link 32-bit code.
3312 if (getToolChain().getArchName() == "i386") {
3313 CmdArgs
.push_back("-m");
3314 CmdArgs
.push_back("elf_i386");
3317 if (Output
.isFilename()) {
3318 CmdArgs
.push_back("-o");
3319 CmdArgs
.push_back(Output
.getFilename());
3321 assert(Output
.isNothing() && "Invalid output.");
3324 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3325 !Args
.hasArg(options::OPT_nostartfiles
)) {
3326 if (!Args
.hasArg(options::OPT_shared
)) {
3327 CmdArgs
.push_back(Args
.MakeArgString(
3328 getToolChain().GetFilePath("crt0.o")));
3329 CmdArgs
.push_back(Args
.MakeArgString(
3330 getToolChain().GetFilePath("crti.o")));
3331 CmdArgs
.push_back(Args
.MakeArgString(
3332 getToolChain().GetFilePath("crtbegin.o")));
3334 CmdArgs
.push_back(Args
.MakeArgString(
3335 getToolChain().GetFilePath("crti.o")));
3336 CmdArgs
.push_back(Args
.MakeArgString(
3337 getToolChain().GetFilePath("crtbeginS.o")));
3341 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3342 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3343 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3344 Args
.AddAllArgs(CmdArgs
, options::OPT_s
);
3345 Args
.AddAllArgs(CmdArgs
, options::OPT_t
);
3346 Args
.AddAllArgs(CmdArgs
, options::OPT_Z_Flag
);
3347 Args
.AddAllArgs(CmdArgs
, options::OPT_r
);
3349 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3351 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3352 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3354 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3355 CmdArgs
.push_back("-lm");
3357 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
3358 // the default system libraries. Just mimic this for now.
3359 CmdArgs
.push_back("-lgcc");
3360 if (Args
.hasArg(options::OPT_static
)) {
3361 CmdArgs
.push_back("-lgcc_eh");
3363 CmdArgs
.push_back("--as-needed");
3364 CmdArgs
.push_back("-lgcc_s");
3365 CmdArgs
.push_back("--no-as-needed");
3368 if (Args
.hasArg(options::OPT_pthread
))
3369 CmdArgs
.push_back("-lpthread");
3370 CmdArgs
.push_back("-lc");
3372 CmdArgs
.push_back("-lgcc");
3373 if (Args
.hasArg(options::OPT_static
)) {
3374 CmdArgs
.push_back("-lgcc_eh");
3376 CmdArgs
.push_back("--as-needed");
3377 CmdArgs
.push_back("-lgcc_s");
3378 CmdArgs
.push_back("--no-as-needed");
3382 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3383 !Args
.hasArg(options::OPT_nostartfiles
)) {
3384 if (!Args
.hasArg(options::OPT_shared
))
3385 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3388 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3390 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3395 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3396 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3399 void linuxtools::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3400 const InputInfo
&Output
,
3401 const InputInfoList
&Inputs
,
3402 const ArgList
&Args
,
3403 const char *LinkingOutput
) const {
3404 ArgStringList CmdArgs
;
3406 // Add --32/--64 to make sure we get the format we want.
3407 // This is incomplete
3408 if (getToolChain().getArch() == llvm::Triple::x86
) {
3409 CmdArgs
.push_back("--32");
3410 } else if (getToolChain().getArch() == llvm::Triple::x86_64
) {
3411 CmdArgs
.push_back("--64");
3412 } else if (getToolChain().getArch() == llvm::Triple::arm
) {
3413 llvm::StringRef MArch
= getToolChain().getArchName();
3414 if (MArch
== "armv7" || MArch
== "armv7a" || MArch
== "armv7-a")
3415 CmdArgs
.push_back("-mfpu=neon");
3418 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3419 options::OPT_Xassembler
);
3421 CmdArgs
.push_back("-o");
3422 CmdArgs
.push_back(Output
.getFilename());
3424 for (InputInfoList::const_iterator
3425 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3426 const InputInfo
&II
= *it
;
3427 CmdArgs
.push_back(II
.getFilename());
3431 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3432 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3435 void linuxtools::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3436 const InputInfo
&Output
,
3437 const InputInfoList
&Inputs
,
3438 const ArgList
&Args
,
3439 const char *LinkingOutput
) const {
3440 const toolchains::Linux
& ToolChain
=
3441 static_cast<const toolchains::Linux
&>(getToolChain());
3442 const Driver
&D
= ToolChain
.getDriver();
3443 ArgStringList CmdArgs
;
3445 // Silence warning for "clang -g foo.o -o foo"
3446 Args
.ClaimAllArgs(options::OPT_g_Group
);
3447 // and for "clang -g foo.o -o foo". Other warning options are already
3448 // handled somewhere else.
3449 Args
.ClaimAllArgs(options::OPT_w
);
3451 if (Arg
*A
= Args
.getLastArg(options::OPT__sysroot_EQ
)) {
3452 CmdArgs
.push_back("--sysroot");
3453 CmdArgs
.push_back(A
->getValue(Args
));
3456 if (Args
.hasArg(options::OPT_pie
))
3457 CmdArgs
.push_back("-pie");
3459 if (Args
.hasArg(options::OPT_rdynamic
))
3460 CmdArgs
.push_back("-export-dynamic");
3462 if (Args
.hasArg(options::OPT_s
))
3463 CmdArgs
.push_back("-s");
3465 for (std::vector
<std::string
>::const_iterator i
= ToolChain
.ExtraOpts
.begin(),
3466 e
= ToolChain
.ExtraOpts
.end();
3468 CmdArgs
.push_back(i
->c_str());
3470 if (!Args
.hasArg(options::OPT_static
)) {
3471 CmdArgs
.push_back("--eh-frame-hdr");
3474 CmdArgs
.push_back("-m");
3475 if (ToolChain
.getArch() == llvm::Triple::x86
)
3476 CmdArgs
.push_back("elf_i386");
3477 else if (ToolChain
.getArch() == llvm::Triple::arm
)
3478 CmdArgs
.push_back("armelf_linux_eabi");
3480 CmdArgs
.push_back("elf_x86_64");
3482 if (Args
.hasArg(options::OPT_static
)) {
3483 if (ToolChain
.getArch() == llvm::Triple::arm
)
3484 CmdArgs
.push_back("-Bstatic");
3486 CmdArgs
.push_back("-static");
3487 } else if (Args
.hasArg(options::OPT_shared
)) {
3488 CmdArgs
.push_back("-shared");
3491 if (ToolChain
.getArch() == llvm::Triple::arm
||
3492 (!Args
.hasArg(options::OPT_static
) &&
3493 !Args
.hasArg(options::OPT_shared
))) {
3494 CmdArgs
.push_back("-dynamic-linker");
3495 if (ToolChain
.getArch() == llvm::Triple::x86
)
3496 CmdArgs
.push_back("/lib/ld-linux.so.2");
3497 else if (ToolChain
.getArch() == llvm::Triple::arm
)
3498 CmdArgs
.push_back("/lib/ld-linux.so.3");
3500 CmdArgs
.push_back("/lib64/ld-linux-x86-64.so.2");
3503 CmdArgs
.push_back("-o");
3504 CmdArgs
.push_back(Output
.getFilename());
3506 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3507 !Args
.hasArg(options::OPT_nostartfiles
)) {
3508 const char *crt1
= NULL
;
3509 if (!Args
.hasArg(options::OPT_shared
)){
3510 if (Args
.hasArg(options::OPT_pie
))
3516 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath(crt1
)));
3518 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath("crti.o")));
3520 const char *crtbegin
;
3521 if (Args
.hasArg(options::OPT_static
))
3522 crtbegin
= "crtbeginT.o";
3523 else if (Args
.hasArg(options::OPT_shared
) || Args
.hasArg(options::OPT_pie
))
3524 crtbegin
= "crtbeginS.o";
3526 crtbegin
= "crtbegin.o";
3527 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath(crtbegin
)));
3530 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3532 const ToolChain::path_list Paths
= ToolChain
.getFilePaths();
3534 for (ToolChain::path_list::const_iterator i
= Paths
.begin(),
3537 const std::string
&s
= *i
;
3538 CmdArgs
.push_back(Args
.MakeArgString(std::string("-L") + s
));
3541 AddLinkerInputs(ToolChain
, Inputs
, Args
, CmdArgs
);
3543 if (D
.CCCIsCXX
&& !Args
.hasArg(options::OPT_nostdlib
)) {
3544 ToolChain
.AddCXXStdlibLibArgs(Args
, CmdArgs
);
3545 CmdArgs
.push_back("-lm");
3548 if (Args
.hasArg(options::OPT_static
))
3549 CmdArgs
.push_back("--start-group");
3551 if (!Args
.hasArg(options::OPT_nostdlib
)) {
3553 CmdArgs
.push_back("-lgcc");
3555 if (Args
.hasArg(options::OPT_static
)) {
3557 CmdArgs
.push_back("-lgcc");
3560 CmdArgs
.push_back("--as-needed");
3561 CmdArgs
.push_back("-lgcc_s");
3563 CmdArgs
.push_back("--no-as-needed");
3566 if (Args
.hasArg(options::OPT_static
))
3567 CmdArgs
.push_back("-lgcc_eh");
3568 else if (!Args
.hasArg(options::OPT_shared
) && D
.CCCIsCXX
)
3569 CmdArgs
.push_back("-lgcc");
3571 if (Args
.hasArg(options::OPT_pthread
) ||
3572 Args
.hasArg(options::OPT_pthreads
))
3573 CmdArgs
.push_back("-lpthread");
3575 CmdArgs
.push_back("-lc");
3577 if (Args
.hasArg(options::OPT_static
))
3578 CmdArgs
.push_back("--end-group");
3581 CmdArgs
.push_back("-lgcc");
3584 CmdArgs
.push_back("--as-needed");
3585 CmdArgs
.push_back("-lgcc_s");
3587 CmdArgs
.push_back("--no-as-needed");
3589 if (!Args
.hasArg(options::OPT_shared
) && D
.CCCIsCXX
)
3590 CmdArgs
.push_back("-lgcc");
3594 if (!Args
.hasArg(options::OPT_nostartfiles
)) {
3596 if (Args
.hasArg(options::OPT_shared
) || Args
.hasArg(options::OPT_pie
))
3597 crtend
= "crtendS.o";
3599 crtend
= "crtend.o";
3601 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath(crtend
)));
3602 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath("crtn.o")));
3606 if (Args
.hasArg(options::OPT_use_gold_plugin
)) {
3607 CmdArgs
.push_back("-plugin");
3608 std::string Plugin
= ToolChain
.getDriver().Dir
+ "/../lib/LLVMgold.so";
3609 CmdArgs
.push_back(Args
.MakeArgString(Plugin
));
3612 C
.addCommand(new Command(JA
, *this, ToolChain
.Linker
.c_str(), CmdArgs
));
3615 void minix::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3616 const InputInfo
&Output
,
3617 const InputInfoList
&Inputs
,
3618 const ArgList
&Args
,
3619 const char *LinkingOutput
) const {
3620 ArgStringList CmdArgs
;
3622 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3623 options::OPT_Xassembler
);
3625 CmdArgs
.push_back("-o");
3626 CmdArgs
.push_back(Output
.getFilename());
3628 for (InputInfoList::const_iterator
3629 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3630 const InputInfo
&II
= *it
;
3631 CmdArgs
.push_back(II
.getFilename());
3635 Args
.MakeArgString(getToolChain().GetProgramPath("gas"));
3636 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3639 void minix::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3640 const InputInfo
&Output
,
3641 const InputInfoList
&Inputs
,
3642 const ArgList
&Args
,
3643 const char *LinkingOutput
) const {
3644 const Driver
&D
= getToolChain().getDriver();
3645 ArgStringList CmdArgs
;
3647 if (Output
.isFilename()) {
3648 CmdArgs
.push_back("-o");
3649 CmdArgs
.push_back(Output
.getFilename());
3651 assert(Output
.isNothing() && "Invalid output.");
3654 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3655 !Args
.hasArg(options::OPT_nostartfiles
))
3656 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3657 "/usr/gnu/lib/crtso.o")));
3659 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3660 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3661 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3663 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3665 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3666 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3668 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3669 CmdArgs
.push_back("-lm");
3672 if (Args
.hasArg(options::OPT_pthread
))
3673 CmdArgs
.push_back("-lpthread");
3674 CmdArgs
.push_back("-lc");
3675 CmdArgs
.push_back("-lgcc");
3676 CmdArgs
.push_back("-L/usr/gnu/lib");
3677 // FIXME: fill in the correct search path for the final
3678 // support libraries.
3679 CmdArgs
.push_back("-L/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
3682 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3683 !Args
.hasArg(options::OPT_nostartfiles
)) {
3684 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3685 "/usr/gnu/lib/libend.a")));
3689 Args
.MakeArgString(getToolChain().GetProgramPath("/usr/gnu/bin/gld"));
3690 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3695 // For now, DragonFly Assemble does just about the same as for
3696 // FreeBSD, but this may change soon.
3697 void dragonfly::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3698 const InputInfo
&Output
,
3699 const InputInfoList
&Inputs
,
3700 const ArgList
&Args
,
3701 const char *LinkingOutput
) const {
3702 ArgStringList CmdArgs
;
3704 // When building 32-bit code on DragonFly/pc64, we have to explicitly
3705 // instruct as in the base system to assemble 32-bit code.
3706 if (getToolChain().getArchName() == "i386")
3707 CmdArgs
.push_back("--32");
3709 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3710 options::OPT_Xassembler
);
3712 CmdArgs
.push_back("-o");
3713 CmdArgs
.push_back(Output
.getFilename());
3715 for (InputInfoList::const_iterator
3716 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3717 const InputInfo
&II
= *it
;
3718 CmdArgs
.push_back(II
.getFilename());
3722 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3723 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3726 void dragonfly::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3727 const InputInfo
&Output
,
3728 const InputInfoList
&Inputs
,
3729 const ArgList
&Args
,
3730 const char *LinkingOutput
) const {
3731 const Driver
&D
= getToolChain().getDriver();
3732 ArgStringList CmdArgs
;
3734 if (Args
.hasArg(options::OPT_static
)) {
3735 CmdArgs
.push_back("-Bstatic");
3737 if (Args
.hasArg(options::OPT_shared
))
3738 CmdArgs
.push_back("-Bshareable");
3740 CmdArgs
.push_back("-dynamic-linker");
3741 CmdArgs
.push_back("/usr/libexec/ld-elf.so.2");
3745 // When building 32-bit code on DragonFly/pc64, we have to explicitly
3746 // instruct ld in the base system to link 32-bit code.
3747 if (getToolChain().getArchName() == "i386") {
3748 CmdArgs
.push_back("-m");
3749 CmdArgs
.push_back("elf_i386");
3752 if (Output
.isFilename()) {
3753 CmdArgs
.push_back("-o");
3754 CmdArgs
.push_back(Output
.getFilename());
3756 assert(Output
.isNothing() && "Invalid output.");
3759 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3760 !Args
.hasArg(options::OPT_nostartfiles
)) {
3761 if (!Args
.hasArg(options::OPT_shared
)) {
3763 Args
.MakeArgString(getToolChain().GetFilePath("crt1.o")));
3765 Args
.MakeArgString(getToolChain().GetFilePath("crti.o")));
3767 Args
.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
3770 Args
.MakeArgString(getToolChain().GetFilePath("crti.o")));
3772 Args
.MakeArgString(getToolChain().GetFilePath("crtbeginS.o")));
3776 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3777 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3778 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3780 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3782 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3783 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3784 // FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of
3786 CmdArgs
.push_back("-L/usr/lib/gcc41");
3788 if (!Args
.hasArg(options::OPT_static
)) {
3789 CmdArgs
.push_back("-rpath");
3790 CmdArgs
.push_back("/usr/lib/gcc41");
3792 CmdArgs
.push_back("-rpath-link");
3793 CmdArgs
.push_back("/usr/lib/gcc41");
3795 CmdArgs
.push_back("-rpath");
3796 CmdArgs
.push_back("/usr/lib");
3798 CmdArgs
.push_back("-rpath-link");
3799 CmdArgs
.push_back("/usr/lib");
3803 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3804 CmdArgs
.push_back("-lm");
3807 if (Args
.hasArg(options::OPT_shared
)) {
3808 CmdArgs
.push_back("-lgcc_pic");
3810 CmdArgs
.push_back("-lgcc");
3814 if (Args
.hasArg(options::OPT_pthread
))
3815 CmdArgs
.push_back("-lpthread");
3817 if (!Args
.hasArg(options::OPT_nolibc
)) {
3818 CmdArgs
.push_back("-lc");
3821 if (Args
.hasArg(options::OPT_shared
)) {
3822 CmdArgs
.push_back("-lgcc_pic");
3824 CmdArgs
.push_back("-lgcc");
3828 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3829 !Args
.hasArg(options::OPT_nostartfiles
)) {
3830 if (!Args
.hasArg(options::OPT_shared
))
3831 CmdArgs
.push_back(Args
.MakeArgString(
3832 getToolChain().GetFilePath("crtend.o")));
3834 CmdArgs
.push_back(Args
.MakeArgString(
3835 getToolChain().GetFilePath("crtendS.o")));
3836 CmdArgs
.push_back(Args
.MakeArgString(
3837 getToolChain().GetFilePath("crtn.o")));
3841 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3842 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3845 void visualstudio::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3846 const InputInfo
&Output
,
3847 const InputInfoList
&Inputs
,
3848 const ArgList
&Args
,
3849 const char *LinkingOutput
) const {
3850 ArgStringList CmdArgs
;
3852 if (Output
.isFilename()) {
3853 CmdArgs
.push_back(Args
.MakeArgString(std::string("-out:") +
3854 Output
.getFilename()));
3856 assert(Output
.isNothing() && "Invalid output.");
3859 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3860 !Args
.hasArg(options::OPT_nostartfiles
)) {
3861 CmdArgs
.push_back("-defaultlib:libcmt");
3864 CmdArgs
.push_back("-nologo");
3866 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3869 Args
.MakeArgString(getToolChain().GetProgramPath("link.exe"));
3870 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));