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.
925 CmdArgs
.push_back("-analyzer-checker=core");
926 if (getToolChain().getTriple().getOS() != llvm::Triple::Win32
)
927 CmdArgs
.push_back("-analyzer-checker=unix");
928 if (getToolChain().getTriple().getVendor() == llvm::Triple::Apple
)
929 CmdArgs
.push_back("-analyzer-checker=macosx");
931 // Checks to perform for Objective-C/Objective-C++.
932 if (types::isObjC(InputType
)) {
933 // Enable all checkers in 'cocoa' package.
934 CmdArgs
.push_back("-analyzer-checker=cocoa");
937 // Checks to perform for all languages *except* C++.
938 if (!types::isCXX(InputType
)) {
939 // NOTE: Leaving -analyzer-check-objc-mem here is intentional.
940 // It also checks C code.
941 CmdArgs
.push_back("-analyzer-check-objc-mem");
943 CmdArgs
.push_back("-analyzer-eagerly-assume");
947 // Set the output format. The default is plist, for (lame) historical
949 CmdArgs
.push_back("-analyzer-output");
950 if (Arg
*A
= Args
.getLastArg(options::OPT__analyzer_output
))
951 CmdArgs
.push_back(A
->getValue(Args
));
953 CmdArgs
.push_back("plist");
955 // Disable the presentation of standard compiler warnings when
956 // using --analyze. We only want to show static analyzer diagnostics
957 // or frontend errors.
958 CmdArgs
.push_back("-w");
960 // Add -Xanalyzer arguments when running as analyzer.
961 Args
.AddAllArgValues(CmdArgs
, options::OPT_Xanalyzer
);
964 CheckCodeGenerationOptions(D
, Args
);
966 // Perform argument translation for LLVM backend. This
967 // takes some care in reconciling with llvm-gcc. The
968 // issue is that llvm-gcc translates these options based on
969 // the values in cc1, whereas we are processing based on
970 // the driver arguments.
972 // This comes from the default translation the driver + cc1
973 // would do to enable flag_pic.
975 // FIXME: Centralize this code.
976 bool PICEnabled
= (Args
.hasArg(options::OPT_fPIC
) ||
977 Args
.hasArg(options::OPT_fpic
) ||
978 Args
.hasArg(options::OPT_fPIE
) ||
979 Args
.hasArg(options::OPT_fpie
));
980 bool PICDisabled
= (Args
.hasArg(options::OPT_mkernel
) ||
981 Args
.hasArg(options::OPT_static
));
982 const char *Model
= getToolChain().GetForcedPicModel();
984 if (Args
.hasArg(options::OPT_mdynamic_no_pic
))
985 Model
= "dynamic-no-pic";
986 else if (PICDisabled
)
991 Model
= getToolChain().GetDefaultRelocationModel();
993 if (llvm::StringRef(Model
) != "pic") {
994 CmdArgs
.push_back("-mrelocation-model");
995 CmdArgs
.push_back(Model
);
998 // Infer the __PIC__ value.
1000 // FIXME: This isn't quite right on Darwin, which always sets
1002 if (strcmp(Model
, "pic") == 0 || strcmp(Model
, "dynamic-no-pic") == 0) {
1003 CmdArgs
.push_back("-pic-level");
1004 CmdArgs
.push_back(Args
.hasArg(options::OPT_fPIC
) ? "2" : "1");
1006 if (!Args
.hasFlag(options::OPT_fmerge_all_constants
,
1007 options::OPT_fno_merge_all_constants
))
1008 CmdArgs
.push_back("-no-merge-all-constants");
1010 // LLVM Code Generator Options.
1012 if (Arg
*A
= Args
.getLastArg(options::OPT_mregparm_EQ
)) {
1013 CmdArgs
.push_back("-mregparm");
1014 CmdArgs
.push_back(A
->getValue(Args
));
1017 // FIXME: Set --enable-unsafe-fp-math.
1018 if (Args
.hasFlag(options::OPT_fno_omit_frame_pointer
,
1019 options::OPT_fomit_frame_pointer
))
1020 CmdArgs
.push_back("-mdisable-fp-elim");
1021 if (!Args
.hasFlag(options::OPT_fzero_initialized_in_bss
,
1022 options::OPT_fno_zero_initialized_in_bss
))
1023 CmdArgs
.push_back("-mno-zero-initialized-in-bss");
1024 if (!Args
.hasFlag(options::OPT_fstrict_aliasing
,
1025 options::OPT_fno_strict_aliasing
,
1026 getToolChain().IsStrictAliasingDefault()))
1027 CmdArgs
.push_back("-relaxed-aliasing");
1029 // Decide whether to use verbose asm. Verbose assembly is the default on
1030 // toolchains which have the integrated assembler on by default.
1031 bool IsVerboseAsmDefault
= getToolChain().IsIntegratedAssemblerDefault();
1032 if (Args
.hasFlag(options::OPT_fverbose_asm
, options::OPT_fno_verbose_asm
,
1033 IsVerboseAsmDefault
) ||
1034 Args
.hasArg(options::OPT_dA
))
1035 CmdArgs
.push_back("-masm-verbose");
1037 if (Args
.hasArg(options::OPT_fdebug_pass_structure
)) {
1038 CmdArgs
.push_back("-mdebug-pass");
1039 CmdArgs
.push_back("Structure");
1041 if (Args
.hasArg(options::OPT_fdebug_pass_arguments
)) {
1042 CmdArgs
.push_back("-mdebug-pass");
1043 CmdArgs
.push_back("Arguments");
1046 // Enable -mconstructor-aliases except on darwin, where we have to
1047 // work around a linker bug; see <rdar://problem/7651567>.
1048 if (getToolChain().getTriple().getOS() != llvm::Triple::Darwin
)
1049 CmdArgs
.push_back("-mconstructor-aliases");
1051 if (Args
.hasArg(options::OPT_mms_bitfields
)) {
1052 CmdArgs
.push_back("-mms-bitfields");
1055 // This is a coarse approximation of what llvm-gcc actually does, both
1056 // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
1057 // complicated ways.
1058 bool AsynchronousUnwindTables
=
1059 Args
.hasFlag(options::OPT_fasynchronous_unwind_tables
,
1060 options::OPT_fno_asynchronous_unwind_tables
,
1061 getToolChain().IsUnwindTablesDefault() &&
1063 if (Args
.hasFlag(options::OPT_funwind_tables
, options::OPT_fno_unwind_tables
,
1064 AsynchronousUnwindTables
))
1065 CmdArgs
.push_back("-munwind-tables");
1067 if (Arg
*A
= Args
.getLastArg(options::OPT_flimited_precision_EQ
)) {
1068 CmdArgs
.push_back("-mlimit-float-precision");
1069 CmdArgs
.push_back(A
->getValue(Args
));
1072 // FIXME: Handle -mtune=.
1073 (void) Args
.hasArg(options::OPT_mtune_EQ
);
1075 if (Arg
*A
= Args
.getLastArg(options::OPT_mcmodel_EQ
)) {
1076 CmdArgs
.push_back("-mcode-model");
1077 CmdArgs
.push_back(A
->getValue(Args
));
1080 // Add target specific cpu and features flags.
1081 switch(getToolChain().getTriple().getArch()) {
1085 case llvm::Triple::arm
:
1086 case llvm::Triple::thumb
:
1087 AddARMTargetArgs(Args
, CmdArgs
);
1090 case llvm::Triple::mips
:
1091 case llvm::Triple::mipsel
:
1092 AddMIPSTargetArgs(Args
, CmdArgs
);
1095 case llvm::Triple::sparc
:
1096 AddSparcTargetArgs(Args
, CmdArgs
);
1099 case llvm::Triple::x86
:
1100 case llvm::Triple::x86_64
:
1101 AddX86TargetArgs(Args
, CmdArgs
);
1105 // Pass the linker version in use.
1106 if (Arg
*A
= Args
.getLastArg(options::OPT_mlinker_version_EQ
)) {
1107 CmdArgs
.push_back("-target-linker-version");
1108 CmdArgs
.push_back(A
->getValue(Args
));
1111 // -mno-omit-leaf-frame-pointer is the default on Darwin.
1112 if (Args
.hasFlag(options::OPT_momit_leaf_frame_pointer
,
1113 options::OPT_mno_omit_leaf_frame_pointer
,
1114 getToolChain().getTriple().getOS() != llvm::Triple::Darwin
))
1115 CmdArgs
.push_back("-momit-leaf-frame-pointer");
1117 // -fno-math-errno is default.
1118 if (Args
.hasFlag(options::OPT_fmath_errno
,
1119 options::OPT_fno_math_errno
,
1121 CmdArgs
.push_back("-fmath-errno");
1123 // Explicitly error on some things we know we don't support and can't just
1125 types::ID InputType
= Inputs
[0].getType();
1126 if (!Args
.hasArg(options::OPT_fallow_unsupported
)) {
1128 if ((Unsupported
= Args
.getLastArg(options::OPT_MG
)) ||
1129 (Unsupported
= Args
.getLastArg(options::OPT_iframework
)))
1130 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1131 << Unsupported
->getOption().getName();
1133 if (types::isCXX(InputType
) &&
1134 getToolChain().getTriple().getOS() == llvm::Triple::Darwin
&&
1135 getToolChain().getTriple().getArch() == llvm::Triple::x86
) {
1136 if ((Unsupported
= Args
.getLastArg(options::OPT_fapple_kext
)))
1137 D
.Diag(clang::diag::err_drv_clang_unsupported_opt_cxx_darwin_i386
)
1138 << Unsupported
->getOption().getName();
1142 Args
.AddAllArgs(CmdArgs
, options::OPT_v
);
1143 Args
.AddLastArg(CmdArgs
, options::OPT_H
);
1144 if (D
.CCPrintHeaders
) {
1145 CmdArgs
.push_back("-header-include-file");
1146 CmdArgs
.push_back(D
.CCPrintHeadersFilename
?
1147 D
.CCPrintHeadersFilename
: "-");
1149 Args
.AddLastArg(CmdArgs
, options::OPT_P
);
1150 Args
.AddLastArg(CmdArgs
, options::OPT_print_ivar_layout
);
1152 // Special case debug options to only pass -g to clang. This is
1154 Args
.ClaimAllArgs(options::OPT_g_Group
);
1155 if (Arg
*A
= Args
.getLastArg(options::OPT_g_Group
))
1156 if (!A
->getOption().matches(options::OPT_g0
))
1157 CmdArgs
.push_back("-g");
1159 Args
.AddAllArgs(CmdArgs
, options::OPT_ffunction_sections
);
1160 Args
.AddAllArgs(CmdArgs
, options::OPT_fdata_sections
);
1162 Args
.AddAllArgs(CmdArgs
, options::OPT_finstrument_functions
);
1164 Args
.AddLastArg(CmdArgs
, options::OPT_nostdinc
);
1165 Args
.AddLastArg(CmdArgs
, options::OPT_nostdincxx
);
1166 Args
.AddLastArg(CmdArgs
, options::OPT_nobuiltininc
);
1168 // Pass the path to compiler resource files.
1169 CmdArgs
.push_back("-resource-dir");
1170 CmdArgs
.push_back(D
.ResourceDir
.c_str());
1172 Args
.AddLastArg(CmdArgs
, options::OPT_working_directory
);
1174 // Add preprocessing options like -I, -D, etc. if we are using the
1177 // FIXME: Support -fpreprocessed
1178 if (types::getPreprocessedType(InputType
) != types::TY_INVALID
)
1179 AddPreprocessingOptions(D
, Args
, CmdArgs
, Output
, Inputs
);
1181 // Manually translate -O to -O2 and -O4 to -O3; let clang reject
1183 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
)) {
1184 if (A
->getOption().matches(options::OPT_O4
))
1185 CmdArgs
.push_back("-O3");
1186 else if (A
->getOption().matches(options::OPT_O
) &&
1187 A
->getValue(Args
)[0] == '\0')
1188 CmdArgs
.push_back("-O2");
1189 else if (A
->getOption().matches(options::OPT_O
) &&
1190 A
->getValue(Args
)[0] == 'z' &&
1191 A
->getValue(Args
)[1] == '\0')
1192 CmdArgs
.push_back("-Os");
1194 A
->render(Args
, CmdArgs
);
1197 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
);
1198 Args
.AddLastArg(CmdArgs
, options::OPT_pedantic
);
1199 Args
.AddLastArg(CmdArgs
, options::OPT_pedantic_errors
);
1200 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
1202 // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi}
1203 // (-ansi is equivalent to -std=c89).
1205 // If a std is supplied, only add -trigraphs if it follows the
1207 if (Arg
*Std
= Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
1208 if (Std
->getOption().matches(options::OPT_ansi
))
1209 if (types::isCXX(InputType
))
1210 CmdArgs
.push_back("-std=c++98");
1212 CmdArgs
.push_back("-std=c89");
1214 Std
->render(Args
, CmdArgs
);
1216 if (Arg
*A
= Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
,
1217 options::OPT_trigraphs
))
1219 A
->render(Args
, CmdArgs
);
1221 // Honor -std-default.
1223 // FIXME: Clang doesn't correctly handle -std= when the input language
1224 // doesn't match. For the time being just ignore this for C++ inputs;
1225 // eventually we want to do all the standard defaulting here instead of
1226 // splitting it between the driver and clang -cc1.
1227 if (!types::isCXX(InputType
))
1228 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
1229 "-std=", /*Joined=*/true);
1230 Args
.AddLastArg(CmdArgs
, options::OPT_trigraphs
);
1233 // Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'.
1234 if (Arg
*Asm
= Args
.getLastArg(options::OPT_fasm
, options::OPT_fno_asm
)) {
1235 if (Asm
->getOption().matches(options::OPT_fasm
))
1236 CmdArgs
.push_back("-fgnu-keywords");
1238 CmdArgs
.push_back("-fno-gnu-keywords");
1241 if (Arg
*A
= Args
.getLastArg(options::OPT_ftemplate_depth_
)) {
1242 CmdArgs
.push_back("-ftemplate-depth");
1243 CmdArgs
.push_back(A
->getValue(Args
));
1246 if (Arg
*A
= Args
.getLastArg(options::OPT_Wlarge_by_value_copy_EQ
,
1247 options::OPT_Wlarge_by_value_copy_def
)) {
1248 CmdArgs
.push_back("-Wlarge-by-value-copy");
1249 if (A
->getNumValues())
1250 CmdArgs
.push_back(A
->getValue(Args
));
1252 CmdArgs
.push_back("64"); // default value for -Wlarge-by-value-copy.
1255 if (Args
.hasArg(options::OPT__relocatable_pch
))
1256 CmdArgs
.push_back("-relocatable-pch");
1258 if (Arg
*A
= Args
.getLastArg(options::OPT_fconstant_string_class_EQ
)) {
1259 CmdArgs
.push_back("-fconstant-string-class");
1260 CmdArgs
.push_back(A
->getValue(Args
));
1263 if (Arg
*A
= Args
.getLastArg(options::OPT_ftabstop_EQ
)) {
1264 CmdArgs
.push_back("-ftabstop");
1265 CmdArgs
.push_back(A
->getValue(Args
));
1268 CmdArgs
.push_back("-ferror-limit");
1269 if (Arg
*A
= Args
.getLastArg(options::OPT_ferror_limit_EQ
))
1270 CmdArgs
.push_back(A
->getValue(Args
));
1272 CmdArgs
.push_back("19");
1274 if (Arg
*A
= Args
.getLastArg(options::OPT_fmacro_backtrace_limit_EQ
)) {
1275 CmdArgs
.push_back("-fmacro-backtrace-limit");
1276 CmdArgs
.push_back(A
->getValue(Args
));
1279 if (Arg
*A
= Args
.getLastArg(options::OPT_ftemplate_backtrace_limit_EQ
)) {
1280 CmdArgs
.push_back("-ftemplate-backtrace-limit");
1281 CmdArgs
.push_back(A
->getValue(Args
));
1284 // Pass -fmessage-length=.
1285 CmdArgs
.push_back("-fmessage-length");
1286 if (Arg
*A
= Args
.getLastArg(options::OPT_fmessage_length_EQ
)) {
1287 CmdArgs
.push_back(A
->getValue(Args
));
1289 // If -fmessage-length=N was not specified, determine whether this is a
1290 // terminal and, if so, implicitly define -fmessage-length appropriately.
1291 unsigned N
= llvm::sys::Process::StandardErrColumns();
1292 CmdArgs
.push_back(Args
.MakeArgString(llvm::Twine(N
)));
1295 if (const Arg
*A
= Args
.getLastArg(options::OPT_fvisibility_EQ
)) {
1296 CmdArgs
.push_back("-fvisibility");
1297 CmdArgs
.push_back(A
->getValue(Args
));
1300 Args
.AddLastArg(CmdArgs
, options::OPT_fvisibility_inlines_hidden
);
1302 // -fhosted is default.
1303 if (KernelOrKext
|| Args
.hasFlag(options::OPT_ffreestanding
,
1304 options::OPT_fhosted
,
1306 CmdArgs
.push_back("-ffreestanding");
1308 // Forward -f (flag) options which we can pass directly.
1309 Args
.AddLastArg(CmdArgs
, options::OPT_fcatch_undefined_behavior
);
1310 Args
.AddLastArg(CmdArgs
, options::OPT_femit_all_decls
);
1311 Args
.AddLastArg(CmdArgs
, options::OPT_fheinous_gnu_extensions
);
1312 Args
.AddLastArg(CmdArgs
, options::OPT_flimit_debug_info
);
1313 Args
.AddLastArg(CmdArgs
, options::OPT_pg
);
1315 // -flax-vector-conversions is default.
1316 if (!Args
.hasFlag(options::OPT_flax_vector_conversions
,
1317 options::OPT_fno_lax_vector_conversions
))
1318 CmdArgs
.push_back("-fno-lax-vector-conversions");
1320 // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only
1321 // takes precedence.
1322 const Arg
*GCArg
= Args
.getLastArg(options::OPT_fobjc_gc_only
);
1324 GCArg
= Args
.getLastArg(options::OPT_fobjc_gc
);
1326 if (getToolChain().SupportsObjCGC()) {
1327 GCArg
->render(Args
, CmdArgs
);
1329 // FIXME: We should move this to a hard error.
1330 D
.Diag(clang::diag::warn_drv_objc_gc_unsupported
)
1331 << GCArg
->getAsString(Args
);
1335 if (Args
.getLastArg(options::OPT_fapple_kext
))
1336 CmdArgs
.push_back("-fapple-kext");
1338 Args
.AddLastArg(CmdArgs
, options::OPT_fno_show_column
);
1339 Args
.AddLastArg(CmdArgs
, options::OPT_fobjc_sender_dependent_dispatch
);
1340 Args
.AddLastArg(CmdArgs
, options::OPT_fdiagnostics_print_source_range_info
);
1341 Args
.AddLastArg(CmdArgs
, options::OPT_fdiagnostics_parseable_fixits
);
1342 Args
.AddLastArg(CmdArgs
, options::OPT_ftime_report
);
1343 Args
.AddLastArg(CmdArgs
, options::OPT_ftrapv
);
1345 if (Arg
*A
= Args
.getLastArg(options::OPT_ftrapv_handler_EQ
)) {
1346 CmdArgs
.push_back("-ftrapv-handler");
1347 CmdArgs
.push_back(A
->getValue(Args
));
1350 Args
.AddLastArg(CmdArgs
, options::OPT_fwrapv
);
1351 Args
.AddLastArg(CmdArgs
, options::OPT_fwritable_strings
);
1352 Args
.AddLastArg(CmdArgs
, options::OPT_funroll_loops
);
1354 Args
.AddLastArg(CmdArgs
, options::OPT_pthread
);
1356 // -stack-protector=0 is default.
1357 unsigned StackProtectorLevel
= 0;
1358 if (Arg
*A
= Args
.getLastArg(options::OPT_fno_stack_protector
,
1359 options::OPT_fstack_protector_all
,
1360 options::OPT_fstack_protector
)) {
1361 if (A
->getOption().matches(options::OPT_fstack_protector
))
1362 StackProtectorLevel
= 1;
1363 else if (A
->getOption().matches(options::OPT_fstack_protector_all
))
1364 StackProtectorLevel
= 2;
1366 StackProtectorLevel
= getToolChain().GetDefaultStackProtectorLevel();
1367 if (StackProtectorLevel
) {
1368 CmdArgs
.push_back("-stack-protector");
1369 CmdArgs
.push_back(Args
.MakeArgString(llvm::Twine(StackProtectorLevel
)));
1372 // Forward -f options with positive and negative forms; we translate
1375 if (Args
.hasArg(options::OPT_mkernel
)) {
1376 if (!Args
.hasArg(options::OPT_fapple_kext
) && types::isCXX(InputType
))
1377 CmdArgs
.push_back("-fapple-kext");
1378 if (!Args
.hasArg(options::OPT_fbuiltin
))
1379 CmdArgs
.push_back("-fno-builtin");
1381 // -fbuiltin is default.
1382 else if (!Args
.hasFlag(options::OPT_fbuiltin
, options::OPT_fno_builtin
))
1383 CmdArgs
.push_back("-fno-builtin");
1385 if (!Args
.hasFlag(options::OPT_fassume_sane_operator_new
,
1386 options::OPT_fno_assume_sane_operator_new
))
1387 CmdArgs
.push_back("-fno-assume-sane-operator-new");
1389 // -fblocks=0 is default.
1390 if (Args
.hasFlag(options::OPT_fblocks
, options::OPT_fno_blocks
,
1391 getToolChain().IsBlocksDefault())) {
1392 CmdArgs
.push_back("-fblocks");
1395 // -faccess-control is default.
1396 if (Args
.hasFlag(options::OPT_fno_access_control
,
1397 options::OPT_faccess_control
,
1399 CmdArgs
.push_back("-fno-access-control");
1401 // -felide-constructors is the default.
1402 if (Args
.hasFlag(options::OPT_fno_elide_constructors
,
1403 options::OPT_felide_constructors
,
1405 CmdArgs
.push_back("-fno-elide-constructors");
1407 // -fexceptions=0 is default.
1408 if (!KernelOrKext
&&
1409 needsExceptions(Args
, InputType
, getToolChain().getTriple()))
1410 CmdArgs
.push_back("-fexceptions");
1412 if (getToolChain().UseSjLjExceptions())
1413 CmdArgs
.push_back("-fsjlj-exceptions");
1415 // -frtti is default.
1417 !Args
.hasFlag(options::OPT_frtti
, options::OPT_fno_rtti
))
1418 CmdArgs
.push_back("-fno-rtti");
1420 // -fshort-enums=0 is default.
1421 // FIXME: Are there targers where -fshort-enums is on by default ?
1422 if (Args
.hasFlag(options::OPT_fshort_enums
,
1423 options::OPT_fno_short_enums
, false))
1424 CmdArgs
.push_back("-fshort-enums");
1426 // -fsigned-char is default.
1427 if (!Args
.hasFlag(options::OPT_fsigned_char
, options::OPT_funsigned_char
,
1428 isSignedCharDefault(getToolChain().getTriple())))
1429 CmdArgs
.push_back("-fno-signed-char");
1431 // -fthreadsafe-static is default.
1432 if (!Args
.hasFlag(options::OPT_fthreadsafe_statics
,
1433 options::OPT_fno_threadsafe_statics
))
1434 CmdArgs
.push_back("-fno-threadsafe-statics");
1436 // -fuse-cxa-atexit is default.
1438 !Args
.hasFlag(options::OPT_fuse_cxa_atexit
, options::OPT_fno_use_cxa_atexit
,
1439 getToolChain().getTriple().getOS() != llvm::Triple::Cygwin
&&
1440 getToolChain().getTriple().getOS() != llvm::Triple::MinGW32
))
1441 CmdArgs
.push_back("-fno-use-cxa-atexit");
1443 // -fms-extensions=0 is default.
1444 if (Args
.hasFlag(options::OPT_fms_extensions
, options::OPT_fno_ms_extensions
,
1445 getToolChain().getTriple().getOS() == llvm::Triple::Win32
))
1446 CmdArgs
.push_back("-fms-extensions");
1448 // -fmsc-version=1300 is default.
1449 if (Args
.hasFlag(options::OPT_fms_extensions
, options::OPT_fno_ms_extensions
,
1450 getToolChain().getTriple().getOS() == llvm::Triple::Win32
) ||
1451 Args
.hasArg(options::OPT_fmsc_version
)) {
1452 llvm::StringRef msc_ver
= Args
.getLastArgValue(options::OPT_fmsc_version
);
1453 if (msc_ver
.empty())
1454 CmdArgs
.push_back("-fmsc-version=1300");
1456 CmdArgs
.push_back(Args
.MakeArgString("-fmsc-version=" + msc_ver
));
1460 // -fborland-extensions=0 is default.
1461 if (Args
.hasFlag(options::OPT_fborland_extensions
,
1462 options::OPT_fno_borland_extensions
, false))
1463 CmdArgs
.push_back("-fborland-extensions");
1465 // -fgnu-keywords default varies depending on language; only pass if
1467 if (Arg
*A
= Args
.getLastArg(options::OPT_fgnu_keywords
,
1468 options::OPT_fno_gnu_keywords
))
1469 A
->render(Args
, CmdArgs
);
1471 // -fnext-runtime defaults to on Darwin and when rewriting Objective-C, and is
1472 // -the -cc1 default.
1473 bool NeXTRuntimeIsDefault
=
1474 IsRewriter
|| getToolChain().getTriple().getOS() == llvm::Triple::Darwin
;
1475 if (!Args
.hasFlag(options::OPT_fnext_runtime
, options::OPT_fgnu_runtime
,
1476 NeXTRuntimeIsDefault
))
1477 CmdArgs
.push_back("-fgnu-runtime");
1479 // -fobjc-nonfragile-abi=0 is default.
1480 if (types::isObjC(InputType
)) {
1481 // Compute the Objective-C ABI "version" to use. Version numbers are
1482 // slightly confusing for historical reasons:
1483 // 1 - Traditional "fragile" ABI
1484 // 2 - Non-fragile ABI, version 1
1485 // 3 - Non-fragile ABI, version 2
1486 unsigned Version
= 1;
1487 // If -fobjc-abi-version= is present, use that to set the version.
1488 if (Arg
*A
= Args
.getLastArg(options::OPT_fobjc_abi_version_EQ
)) {
1489 if (llvm::StringRef(A
->getValue(Args
)) == "1")
1491 else if (llvm::StringRef(A
->getValue(Args
)) == "2")
1493 else if (llvm::StringRef(A
->getValue(Args
)) == "3")
1496 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
1498 // Otherwise, determine if we are using the non-fragile ABI.
1499 if (Args
.hasFlag(options::OPT_fobjc_nonfragile_abi
,
1500 options::OPT_fno_objc_nonfragile_abi
,
1501 getToolChain().IsObjCNonFragileABIDefault())) {
1502 // Determine the non-fragile ABI version to use.
1503 #ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO
1504 unsigned NonFragileABIVersion
= 1;
1506 unsigned NonFragileABIVersion
= 2;
1509 if (Arg
*A
= Args
.getLastArg(
1510 options::OPT_fobjc_nonfragile_abi_version_EQ
)) {
1511 if (llvm::StringRef(A
->getValue(Args
)) == "1")
1512 NonFragileABIVersion
= 1;
1513 else if (llvm::StringRef(A
->getValue(Args
)) == "2")
1514 NonFragileABIVersion
= 2;
1516 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1517 << A
->getAsString(Args
);
1520 Version
= 1 + NonFragileABIVersion
;
1526 if (Version
== 2 || Version
== 3) {
1527 CmdArgs
.push_back("-fobjc-nonfragile-abi");
1529 // -fobjc-dispatch-method is only relevant with the nonfragile-abi, and
1530 // legacy is the default.
1531 if (!Args
.hasFlag(options::OPT_fobjc_legacy_dispatch
,
1532 options::OPT_fno_objc_legacy_dispatch
,
1533 getToolChain().IsObjCLegacyDispatchDefault())) {
1534 if (getToolChain().UseObjCMixedDispatch())
1535 CmdArgs
.push_back("-fobjc-dispatch-method=mixed");
1537 CmdArgs
.push_back("-fobjc-dispatch-method=non-legacy");
1541 // -fobjc-default-synthesize-properties=0 is default.
1542 if (Args
.hasFlag(options::OPT_fobjc_default_synthesize_properties
,
1543 options::OPT_fno_objc_default_synthesize_properties
,
1544 getToolChain().IsObjCDefaultSynthPropertiesDefault())) {
1545 CmdArgs
.push_back("-fobjc-default-synthesize-properties");
1549 if (!Args
.hasFlag(options::OPT_fassume_sane_operator_new
,
1550 options::OPT_fno_assume_sane_operator_new
))
1551 CmdArgs
.push_back("-fno-assume-sane-operator-new");
1553 // -fconstant-cfstrings is default, and may be subject to argument translation
1555 if (!Args
.hasFlag(options::OPT_fconstant_cfstrings
,
1556 options::OPT_fno_constant_cfstrings
) ||
1557 !Args
.hasFlag(options::OPT_mconstant_cfstrings
,
1558 options::OPT_mno_constant_cfstrings
))
1559 CmdArgs
.push_back("-fno-constant-cfstrings");
1561 // -fshort-wchar default varies depending on platform; only
1562 // pass if specified.
1563 if (Arg
*A
= Args
.getLastArg(options::OPT_fshort_wchar
))
1564 A
->render(Args
, CmdArgs
);
1566 // -fno-pascal-strings is default, only pass non-default. If the tool chain
1567 // happened to translate to -mpascal-strings, we want to back translate here.
1569 // FIXME: This is gross; that translation should be pulled from the
1571 if (Args
.hasFlag(options::OPT_fpascal_strings
,
1572 options::OPT_fno_pascal_strings
,
1574 Args
.hasFlag(options::OPT_mpascal_strings
,
1575 options::OPT_mno_pascal_strings
,
1577 CmdArgs
.push_back("-fpascal-strings");
1579 if (Args
.hasArg(options::OPT_mkernel
) ||
1580 Args
.hasArg(options::OPT_fapple_kext
)) {
1581 if (!Args
.hasArg(options::OPT_fcommon
))
1582 CmdArgs
.push_back("-fno-common");
1584 // -fcommon is default, only pass non-default.
1585 else if (!Args
.hasFlag(options::OPT_fcommon
, options::OPT_fno_common
))
1586 CmdArgs
.push_back("-fno-common");
1588 // -fsigned-bitfields is default, and clang doesn't yet support
1589 // -funsigned-bitfields.
1590 if (!Args
.hasFlag(options::OPT_fsigned_bitfields
,
1591 options::OPT_funsigned_bitfields
))
1592 D
.Diag(clang::diag::warn_drv_clang_unsupported
)
1593 << Args
.getLastArg(options::OPT_funsigned_bitfields
)->getAsString(Args
);
1595 // -fsigned-bitfields is default, and clang doesn't support -fno-for-scope.
1596 if (!Args
.hasFlag(options::OPT_ffor_scope
,
1597 options::OPT_fno_for_scope
))
1598 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1599 << Args
.getLastArg(options::OPT_fno_for_scope
)->getAsString(Args
);
1601 // -fcaret-diagnostics is default.
1602 if (!Args
.hasFlag(options::OPT_fcaret_diagnostics
,
1603 options::OPT_fno_caret_diagnostics
, true))
1604 CmdArgs
.push_back("-fno-caret-diagnostics");
1606 // -fdiagnostics-fixit-info is default, only pass non-default.
1607 if (!Args
.hasFlag(options::OPT_fdiagnostics_fixit_info
,
1608 options::OPT_fno_diagnostics_fixit_info
))
1609 CmdArgs
.push_back("-fno-diagnostics-fixit-info");
1611 // Enable -fdiagnostics-show-option by default.
1612 if (Args
.hasFlag(options::OPT_fdiagnostics_show_option
,
1613 options::OPT_fno_diagnostics_show_option
))
1614 CmdArgs
.push_back("-fdiagnostics-show-option");
1617 Args
.getLastArg(options::OPT_fdiagnostics_show_category_EQ
)) {
1618 CmdArgs
.push_back("-fdiagnostics-show-category");
1619 CmdArgs
.push_back(A
->getValue(Args
));
1622 // Color diagnostics are the default, unless the terminal doesn't support
1624 if (Args
.hasFlag(options::OPT_fcolor_diagnostics
,
1625 options::OPT_fno_color_diagnostics
,
1626 llvm::sys::Process::StandardErrHasColors()))
1627 CmdArgs
.push_back("-fcolor-diagnostics");
1629 if (!Args
.hasFlag(options::OPT_fshow_source_location
,
1630 options::OPT_fno_show_source_location
))
1631 CmdArgs
.push_back("-fno-show-source-location");
1633 if (!Args
.hasFlag(options::OPT_fspell_checking
,
1634 options::OPT_fno_spell_checking
))
1635 CmdArgs
.push_back("-fno-spell-checking");
1638 // Silently ignore -fasm-blocks for now.
1639 (void) Args
.hasFlag(options::OPT_fasm_blocks
, options::OPT_fno_asm_blocks
,
1642 if (Arg
*A
= Args
.getLastArg(options::OPT_fshow_overloads_EQ
))
1643 A
->render(Args
, CmdArgs
);
1645 // -fdollars-in-identifiers default varies depending on platform and
1646 // language; only pass if specified.
1647 if (Arg
*A
= Args
.getLastArg(options::OPT_fdollars_in_identifiers
,
1648 options::OPT_fno_dollars_in_identifiers
)) {
1649 if (A
->getOption().matches(options::OPT_fdollars_in_identifiers
))
1650 CmdArgs
.push_back("-fdollars-in-identifiers");
1652 CmdArgs
.push_back("-fno-dollars-in-identifiers");
1655 // -funit-at-a-time is default, and we don't support -fno-unit-at-a-time for
1656 // practical purposes.
1657 if (Arg
*A
= Args
.getLastArg(options::OPT_funit_at_a_time
,
1658 options::OPT_fno_unit_at_a_time
)) {
1659 if (A
->getOption().matches(options::OPT_fno_unit_at_a_time
))
1660 D
.Diag(clang::diag::warn_drv_clang_unsupported
) << A
->getAsString(Args
);
1663 // Default to -fno-builtin-str{cat,cpy} on Darwin for ARM.
1665 // FIXME: This is disabled until clang -cc1 supports -fno-builtin-foo. PR4941.
1667 if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin
&&
1668 (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
1669 getToolChain().getTriple().getArch() == llvm::Triple::thumb
)) {
1670 if (!Args
.hasArg(options::OPT_fbuiltin_strcat
))
1671 CmdArgs
.push_back("-fno-builtin-strcat");
1672 if (!Args
.hasArg(options::OPT_fbuiltin_strcpy
))
1673 CmdArgs
.push_back("-fno-builtin-strcpy");
1677 if (Arg
*A
= Args
.getLastArg(options::OPT_traditional
,
1678 options::OPT_traditional_cpp
))
1679 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
1681 Args
.AddLastArg(CmdArgs
, options::OPT_dM
);
1682 Args
.AddLastArg(CmdArgs
, options::OPT_dD
);
1684 // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
1686 Args
.AddAllArgValues(CmdArgs
, options::OPT_Xclang
);
1687 for (arg_iterator it
= Args
.filtered_begin(options::OPT_mllvm
),
1688 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
1691 // We translate this by hand to the -cc1 argument, since nightly test uses
1692 // it and developers have been trained to spell it with -mllvm.
1693 if (llvm::StringRef((*it
)->getValue(Args
, 0)) == "-disable-llvm-optzns")
1694 CmdArgs
.push_back("-disable-llvm-optzns");
1696 (*it
)->render(Args
, CmdArgs
);
1699 if (Output
.getType() == types::TY_Dependencies
) {
1700 // Handled with other dependency code.
1701 } else if (Output
.isFilename()) {
1702 CmdArgs
.push_back("-o");
1703 CmdArgs
.push_back(Output
.getFilename());
1705 assert(Output
.isNothing() && "Invalid output.");
1708 for (InputInfoList::const_iterator
1709 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
1710 const InputInfo
&II
= *it
;
1711 CmdArgs
.push_back("-x");
1712 CmdArgs
.push_back(types::getTypeName(II
.getType()));
1713 if (II
.isFilename())
1714 CmdArgs
.push_back(II
.getFilename());
1716 II
.getInputArg().renderAsInput(Args
, CmdArgs
);
1719 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
1721 const char *Exec
= getToolChain().getDriver().getClangProgramPath();
1723 // Optionally embed the -cc1 level arguments into the debug info, for build
1725 if (getToolChain().UseDwarfDebugFlags()) {
1726 ArgStringList OriginalArgs
;
1727 for (ArgList::const_iterator it
= Args
.begin(),
1728 ie
= Args
.end(); it
!= ie
; ++it
)
1729 (*it
)->render(Args
, OriginalArgs
);
1731 llvm::SmallString
<256> Flags
;
1733 for (unsigned i
= 0, e
= OriginalArgs
.size(); i
!= e
; ++i
) {
1735 Flags
+= OriginalArgs
[i
];
1737 CmdArgs
.push_back("-dwarf-debug-flags");
1738 CmdArgs
.push_back(Args
.MakeArgString(Flags
.str()));
1741 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1743 if (Arg
*A
= Args
.getLastArg(options::OPT_pg
))
1744 if (Args
.hasArg(options::OPT_fomit_frame_pointer
))
1745 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
1746 << "-fomit-frame-pointer" << A
->getAsString(Args
);
1748 // Claim some arguments which clang supports automatically.
1750 // -fpch-preprocess is used with gcc to add a special marker in the output to
1751 // include the PCH file. Clang's PTH solution is completely transparent, so we
1752 // do not need to deal with it at all.
1753 Args
.ClaimAllArgs(options::OPT_fpch_preprocess
);
1755 // Claim some arguments which clang doesn't support, but we don't
1756 // care to warn the user about.
1757 Args
.ClaimAllArgs(options::OPT_clang_ignored_f_Group
);
1758 Args
.ClaimAllArgs(options::OPT_clang_ignored_m_Group
);
1761 void ClangAs::ConstructJob(Compilation
&C
, const JobAction
&JA
,
1762 const InputInfo
&Output
,
1763 const InputInfoList
&Inputs
,
1764 const ArgList
&Args
,
1765 const char *LinkingOutput
) const {
1766 ArgStringList CmdArgs
;
1768 assert(Inputs
.size() == 1 && "Unexpected number of inputs.");
1769 const InputInfo
&Input
= Inputs
[0];
1771 // Don't warn about "clang -w -c foo.s"
1772 Args
.ClaimAllArgs(options::OPT_w
);
1774 // Invoke ourselves in -cc1as mode.
1776 // FIXME: Implement custom jobs for internal actions.
1777 CmdArgs
.push_back("-cc1as");
1779 // Add the "effective" target triple.
1780 CmdArgs
.push_back("-triple");
1781 std::string TripleStr
= getToolChain().ComputeEffectiveClangTriple(Args
);
1782 CmdArgs
.push_back(Args
.MakeArgString(TripleStr
));
1784 // Set the output mode, we currently only expect to be used as a real
1786 CmdArgs
.push_back("-filetype");
1787 CmdArgs
.push_back("obj");
1789 // At -O0, we use -mrelax-all by default.
1791 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
))
1792 IsOpt
= !A
->getOption().matches(options::OPT_O0
);
1793 if (Args
.hasFlag(options::OPT_mrelax_all
,
1794 options::OPT_mno_relax_all
,
1796 CmdArgs
.push_back("-relax-all");
1798 // FIXME: Add -force_cpusubtype_ALL support, once we have it.
1800 // FIXME: Add -g support, once we have it.
1802 // FIXME: Add -static support, once we have it.
1804 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
1805 options::OPT_Xassembler
);
1807 assert(Output
.isFilename() && "Unexpected lipo output.");
1808 CmdArgs
.push_back("-o");
1809 CmdArgs
.push_back(Output
.getFilename());
1811 assert(Input
.isFilename() && "Invalid input.");
1812 CmdArgs
.push_back(Input
.getFilename());
1814 const char *Exec
= getToolChain().getDriver().getClangProgramPath();
1815 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1818 void gcc::Common::ConstructJob(Compilation
&C
, const JobAction
&JA
,
1819 const InputInfo
&Output
,
1820 const InputInfoList
&Inputs
,
1821 const ArgList
&Args
,
1822 const char *LinkingOutput
) const {
1823 const Driver
&D
= getToolChain().getDriver();
1824 ArgStringList CmdArgs
;
1826 for (ArgList::const_iterator
1827 it
= Args
.begin(), ie
= Args
.end(); it
!= ie
; ++it
) {
1829 if (A
->getOption().hasForwardToGCC()) {
1830 // Don't forward any -g arguments to assembly steps.
1831 if (isa
<AssembleJobAction
>(JA
) &&
1832 A
->getOption().matches(options::OPT_g_Group
))
1835 // It is unfortunate that we have to claim here, as this means
1836 // we will basically never report anything interesting for
1837 // platforms using a generic gcc, even if we are just using gcc
1838 // to get to the assembler.
1840 A
->render(Args
, CmdArgs
);
1844 RenderExtraToolArgs(JA
, CmdArgs
);
1846 // If using a driver driver, force the arch.
1847 const std::string
&Arch
= getToolChain().getArchName();
1848 if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin
) {
1849 CmdArgs
.push_back("-arch");
1851 // FIXME: Remove these special cases.
1852 if (Arch
== "powerpc")
1853 CmdArgs
.push_back("ppc");
1854 else if (Arch
== "powerpc64")
1855 CmdArgs
.push_back("ppc64");
1857 CmdArgs
.push_back(Args
.MakeArgString(Arch
));
1860 // Try to force gcc to match the tool chain we want, if we recognize
1863 // FIXME: The triple class should directly provide the information we want
1865 if (Arch
== "i386" || Arch
== "powerpc")
1866 CmdArgs
.push_back("-m32");
1867 else if (Arch
== "x86_64" || Arch
== "powerpc64")
1868 CmdArgs
.push_back("-m64");
1870 if (Output
.isFilename()) {
1871 CmdArgs
.push_back("-o");
1872 CmdArgs
.push_back(Output
.getFilename());
1874 assert(Output
.isNothing() && "Unexpected output");
1875 CmdArgs
.push_back("-fsyntax-only");
1879 // Only pass -x if gcc will understand it; otherwise hope gcc
1880 // understands the suffix correctly. The main use case this would go
1881 // wrong in is for linker inputs if they happened to have an odd
1882 // suffix; really the only way to get this to happen is a command
1883 // like '-x foobar a.c' which will treat a.c like a linker input.
1885 // FIXME: For the linker case specifically, can we safely convert
1886 // inputs into '-Wl,' options?
1887 for (InputInfoList::const_iterator
1888 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
1889 const InputInfo
&II
= *it
;
1891 // Don't try to pass LLVM or AST inputs to a generic gcc.
1892 if (II
.getType() == types::TY_LLVM_IR
|| II
.getType() == types::TY_LTO_IR
||
1893 II
.getType() == types::TY_LLVM_BC
|| II
.getType() == types::TY_LTO_BC
)
1894 D
.Diag(clang::diag::err_drv_no_linker_llvm_support
)
1895 << getToolChain().getTripleString();
1896 else if (II
.getType() == types::TY_AST
)
1897 D
.Diag(clang::diag::err_drv_no_ast_support
)
1898 << getToolChain().getTripleString();
1900 if (types::canTypeBeUserSpecified(II
.getType())) {
1901 CmdArgs
.push_back("-x");
1902 CmdArgs
.push_back(types::getTypeName(II
.getType()));
1905 if (II
.isFilename())
1906 CmdArgs
.push_back(II
.getFilename());
1908 const Arg
&A
= II
.getInputArg();
1910 // Reverse translate some rewritten options.
1911 if (A
.getOption().matches(options::OPT_Z_reserved_lib_stdcxx
)) {
1912 CmdArgs
.push_back("-lstdc++");
1916 // Don't render as input, we need gcc to do the translations.
1917 A
.render(Args
, CmdArgs
);
1921 const char *GCCName
= getToolChain().getDriver().getCCCGenericGCCName().c_str();
1923 Args
.MakeArgString(getToolChain().GetProgramPath(GCCName
));
1924 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1927 void gcc::Preprocess::RenderExtraToolArgs(const JobAction
&JA
,
1928 ArgStringList
&CmdArgs
) const {
1929 CmdArgs
.push_back("-E");
1932 void gcc::Precompile::RenderExtraToolArgs(const JobAction
&JA
,
1933 ArgStringList
&CmdArgs
) const {
1934 // The type is good enough.
1937 void gcc::Compile::RenderExtraToolArgs(const JobAction
&JA
,
1938 ArgStringList
&CmdArgs
) const {
1939 const Driver
&D
= getToolChain().getDriver();
1941 // If -flto, etc. are present then make sure not to force assembly output.
1942 if (JA
.getType() == types::TY_LLVM_IR
|| JA
.getType() == types::TY_LTO_IR
||
1943 JA
.getType() == types::TY_LLVM_BC
|| JA
.getType() == types::TY_LTO_BC
)
1944 CmdArgs
.push_back("-c");
1946 if (JA
.getType() != types::TY_PP_Asm
)
1947 D
.Diag(clang::diag::err_drv_invalid_gcc_output_type
)
1948 << getTypeName(JA
.getType());
1950 CmdArgs
.push_back("-S");
1954 void gcc::Assemble::RenderExtraToolArgs(const JobAction
&JA
,
1955 ArgStringList
&CmdArgs
) const {
1956 CmdArgs
.push_back("-c");
1959 void gcc::Link::RenderExtraToolArgs(const JobAction
&JA
,
1960 ArgStringList
&CmdArgs
) const {
1961 // The types are (hopefully) good enough.
1964 const char *darwin::CC1::getCC1Name(types::ID Type
) const {
1967 assert(0 && "Unexpected type for Darwin CC1 tool.");
1969 case types::TY_C
: case types::TY_CHeader
:
1970 case types::TY_PP_C
: case types::TY_PP_CHeader
:
1972 case types::TY_ObjC
: case types::TY_ObjCHeader
:
1973 case types::TY_PP_ObjC
: case types::TY_PP_ObjCHeader
:
1975 case types::TY_CXX
: case types::TY_CXXHeader
:
1976 case types::TY_PP_CXX
: case types::TY_PP_CXXHeader
:
1978 case types::TY_ObjCXX
: case types::TY_ObjCXXHeader
:
1979 case types::TY_PP_ObjCXX
: case types::TY_PP_ObjCXXHeader
:
1980 return "cc1objplus";
1984 const char *darwin::CC1::getBaseInputName(const ArgList
&Args
,
1985 const InputInfoList
&Inputs
) {
1986 return Args
.MakeArgString(
1987 llvm::sys::path::filename(Inputs
[0].getBaseInput()));
1990 const char *darwin::CC1::getBaseInputStem(const ArgList
&Args
,
1991 const InputInfoList
&Inputs
) {
1992 const char *Str
= getBaseInputName(Args
, Inputs
);
1994 if (const char *End
= strrchr(Str
, '.'))
1995 return Args
.MakeArgString(std::string(Str
, End
));
2001 darwin::CC1::getDependencyFileName(const ArgList
&Args
,
2002 const InputInfoList
&Inputs
) {
2003 // FIXME: Think about this more.
2006 if (Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
)) {
2007 std::string
Str(OutputOpt
->getValue(Args
));
2009 Res
= Str
.substr(0, Str
.rfind('.'));
2011 Res
= darwin::CC1::getBaseInputStem(Args
, Inputs
);
2013 return Args
.MakeArgString(Res
+ ".d");
2016 void darwin::CC1::AddCC1Args(const ArgList
&Args
,
2017 ArgStringList
&CmdArgs
) const {
2018 const Driver
&D
= getToolChain().getDriver();
2020 CheckCodeGenerationOptions(D
, Args
);
2022 // Derived from cc1 spec.
2023 if (!Args
.hasArg(options::OPT_mkernel
) && !Args
.hasArg(options::OPT_static
) &&
2024 !Args
.hasArg(options::OPT_mdynamic_no_pic
))
2025 CmdArgs
.push_back("-fPIC");
2027 if (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
2028 getToolChain().getTriple().getArch() == llvm::Triple::thumb
) {
2029 if (!Args
.hasArg(options::OPT_fbuiltin_strcat
))
2030 CmdArgs
.push_back("-fno-builtin-strcat");
2031 if (!Args
.hasArg(options::OPT_fbuiltin_strcpy
))
2032 CmdArgs
.push_back("-fno-builtin-strcpy");
2035 // gcc has some code here to deal with when no -mmacosx-version-min
2036 // and no -miphoneos-version-min is present, but this never happens
2037 // due to tool chain specific argument translation.
2039 if (Args
.hasArg(options::OPT_g_Flag
) &&
2040 !Args
.hasArg(options::OPT_fno_eliminate_unused_debug_symbols
))
2041 CmdArgs
.push_back("-feliminate-unused-debug-symbols");
2044 void darwin::CC1::AddCC1OptionsArgs(const ArgList
&Args
, ArgStringList
&CmdArgs
,
2045 const InputInfoList
&Inputs
,
2046 const ArgStringList
&OutputArgs
) const {
2047 const Driver
&D
= getToolChain().getDriver();
2049 // Derived from cc1_options spec.
2050 if (Args
.hasArg(options::OPT_fast
) ||
2051 Args
.hasArg(options::OPT_fastf
) ||
2052 Args
.hasArg(options::OPT_fastcp
))
2053 CmdArgs
.push_back("-O3");
2055 if (Arg
*A
= Args
.getLastArg(options::OPT_pg
))
2056 if (Args
.hasArg(options::OPT_fomit_frame_pointer
))
2057 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
2058 << A
->getAsString(Args
) << "-fomit-frame-pointer";
2060 AddCC1Args(Args
, CmdArgs
);
2062 if (!Args
.hasArg(options::OPT_Q
))
2063 CmdArgs
.push_back("-quiet");
2065 CmdArgs
.push_back("-dumpbase");
2066 CmdArgs
.push_back(darwin::CC1::getBaseInputName(Args
, Inputs
));
2068 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Group
);
2070 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Group
);
2071 Args
.AddAllArgs(CmdArgs
, options::OPT_a_Group
);
2073 // FIXME: The goal is to use the user provided -o if that is our
2074 // final output, otherwise to drive from the original input
2075 // name. Find a clean way to go about this.
2076 if ((Args
.hasArg(options::OPT_c
) || Args
.hasArg(options::OPT_S
)) &&
2077 Args
.hasArg(options::OPT_o
)) {
2078 Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
);
2079 CmdArgs
.push_back("-auxbase-strip");
2080 CmdArgs
.push_back(OutputOpt
->getValue(Args
));
2082 CmdArgs
.push_back("-auxbase");
2083 CmdArgs
.push_back(darwin::CC1::getBaseInputStem(Args
, Inputs
));
2086 Args
.AddAllArgs(CmdArgs
, options::OPT_g_Group
);
2088 Args
.AddAllArgs(CmdArgs
, options::OPT_O
);
2089 // FIXME: -Wall is getting some special treatment. Investigate.
2090 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
, options::OPT_pedantic_Group
);
2091 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2092 Args
.AddAllArgs(CmdArgs
, options::OPT_std_EQ
, options::OPT_ansi
,
2093 options::OPT_trigraphs
);
2094 if (!Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
2095 // Honor -std-default.
2096 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
2097 "-std=", /*Joined=*/true);
2100 if (Args
.hasArg(options::OPT_v
))
2101 CmdArgs
.push_back("-version");
2102 if (Args
.hasArg(options::OPT_pg
))
2103 CmdArgs
.push_back("-p");
2104 Args
.AddLastArg(CmdArgs
, options::OPT_p
);
2106 // The driver treats -fsyntax-only specially.
2107 if (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
2108 getToolChain().getTriple().getArch() == llvm::Triple::thumb
) {
2109 // Removes -fbuiltin-str{cat,cpy}; these aren't recognized by cc1 but are
2110 // used to inhibit the default -fno-builtin-str{cat,cpy}.
2112 // FIXME: Should we grow a better way to deal with "removing" args?
2113 for (arg_iterator it
= Args
.filtered_begin(options::OPT_f_Group
,
2114 options::OPT_fsyntax_only
),
2115 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
2116 if (!(*it
)->getOption().matches(options::OPT_fbuiltin_strcat
) &&
2117 !(*it
)->getOption().matches(options::OPT_fbuiltin_strcpy
)) {
2119 (*it
)->render(Args
, CmdArgs
);
2123 Args
.AddAllArgs(CmdArgs
, options::OPT_f_Group
, options::OPT_fsyntax_only
);
2125 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
2126 if (Args
.hasArg(options::OPT_Qn
))
2127 CmdArgs
.push_back("-fno-ident");
2129 // FIXME: This isn't correct.
2130 //Args.AddLastArg(CmdArgs, options::OPT__help)
2131 //Args.AddLastArg(CmdArgs, options::OPT__targetHelp)
2133 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2135 // FIXME: Still don't get what is happening here. Investigate.
2136 Args
.AddAllArgs(CmdArgs
, options::OPT__param
);
2138 if (Args
.hasArg(options::OPT_fmudflap
) ||
2139 Args
.hasArg(options::OPT_fmudflapth
)) {
2140 CmdArgs
.push_back("-fno-builtin");
2141 CmdArgs
.push_back("-fno-merge-constants");
2144 if (Args
.hasArg(options::OPT_coverage
)) {
2145 CmdArgs
.push_back("-fprofile-arcs");
2146 CmdArgs
.push_back("-ftest-coverage");
2149 if (types::isCXX(Inputs
[0].getType()))
2150 CmdArgs
.push_back("-D__private_extern__=extern");
2153 void darwin::CC1::AddCPPOptionsArgs(const ArgList
&Args
, ArgStringList
&CmdArgs
,
2154 const InputInfoList
&Inputs
,
2155 const ArgStringList
&OutputArgs
) const {
2156 // Derived from cpp_options
2157 AddCPPUniqueOptionsArgs(Args
, CmdArgs
, Inputs
);
2159 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2161 AddCC1Args(Args
, CmdArgs
);
2163 // NOTE: The code below has some commonality with cpp_options, but
2164 // in classic gcc style ends up sending things in different
2165 // orders. This may be a good merge candidate once we drop pedantic
2168 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Group
);
2169 Args
.AddAllArgs(CmdArgs
, options::OPT_std_EQ
, options::OPT_ansi
,
2170 options::OPT_trigraphs
);
2171 if (!Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
2172 // Honor -std-default.
2173 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
2174 "-std=", /*Joined=*/true);
2176 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
, options::OPT_pedantic_Group
);
2177 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2179 // The driver treats -fsyntax-only specially.
2180 Args
.AddAllArgs(CmdArgs
, options::OPT_f_Group
, options::OPT_fsyntax_only
);
2182 if (Args
.hasArg(options::OPT_g_Group
) && !Args
.hasArg(options::OPT_g0
) &&
2183 !Args
.hasArg(options::OPT_fno_working_directory
))
2184 CmdArgs
.push_back("-fworking-directory");
2186 Args
.AddAllArgs(CmdArgs
, options::OPT_O
);
2187 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
2188 if (Args
.hasArg(options::OPT_save_temps
))
2189 CmdArgs
.push_back("-fpch-preprocess");
2192 void darwin::CC1::AddCPPUniqueOptionsArgs(const ArgList
&Args
,
2193 ArgStringList
&CmdArgs
,
2194 const InputInfoList
&Inputs
) const {
2195 const Driver
&D
= getToolChain().getDriver();
2197 CheckPreprocessingOptions(D
, Args
);
2199 // Derived from cpp_unique_options.
2200 // -{C,CC} only with -E is checked in CheckPreprocessingOptions().
2201 Args
.AddLastArg(CmdArgs
, options::OPT_C
);
2202 Args
.AddLastArg(CmdArgs
, options::OPT_CC
);
2203 if (!Args
.hasArg(options::OPT_Q
))
2204 CmdArgs
.push_back("-quiet");
2205 Args
.AddAllArgs(CmdArgs
, options::OPT_nostdinc
);
2206 Args
.AddAllArgs(CmdArgs
, options::OPT_nostdincxx
);
2207 Args
.AddLastArg(CmdArgs
, options::OPT_v
);
2208 Args
.AddAllArgs(CmdArgs
, options::OPT_I_Group
, options::OPT_F
);
2209 Args
.AddLastArg(CmdArgs
, options::OPT_P
);
2211 // FIXME: Handle %I properly.
2212 if (getToolChain().getArchName() == "x86_64") {
2213 CmdArgs
.push_back("-imultilib");
2214 CmdArgs
.push_back("x86_64");
2217 if (Args
.hasArg(options::OPT_MD
)) {
2218 CmdArgs
.push_back("-MD");
2219 CmdArgs
.push_back(darwin::CC1::getDependencyFileName(Args
, Inputs
));
2222 if (Args
.hasArg(options::OPT_MMD
)) {
2223 CmdArgs
.push_back("-MMD");
2224 CmdArgs
.push_back(darwin::CC1::getDependencyFileName(Args
, Inputs
));
2227 Args
.AddLastArg(CmdArgs
, options::OPT_M
);
2228 Args
.AddLastArg(CmdArgs
, options::OPT_MM
);
2229 Args
.AddAllArgs(CmdArgs
, options::OPT_MF
);
2230 Args
.AddLastArg(CmdArgs
, options::OPT_MG
);
2231 Args
.AddLastArg(CmdArgs
, options::OPT_MP
);
2232 Args
.AddAllArgs(CmdArgs
, options::OPT_MQ
);
2233 Args
.AddAllArgs(CmdArgs
, options::OPT_MT
);
2234 if (!Args
.hasArg(options::OPT_M
) && !Args
.hasArg(options::OPT_MM
) &&
2235 (Args
.hasArg(options::OPT_MD
) || Args
.hasArg(options::OPT_MMD
))) {
2236 if (Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
)) {
2237 CmdArgs
.push_back("-MQ");
2238 CmdArgs
.push_back(OutputOpt
->getValue(Args
));
2242 Args
.AddLastArg(CmdArgs
, options::OPT_remap
);
2243 if (Args
.hasArg(options::OPT_g3
))
2244 CmdArgs
.push_back("-dD");
2245 Args
.AddLastArg(CmdArgs
, options::OPT_H
);
2247 AddCPPArgs(Args
, CmdArgs
);
2249 Args
.AddAllArgs(CmdArgs
, options::OPT_D
, options::OPT_U
, options::OPT_A
);
2250 Args
.AddAllArgs(CmdArgs
, options::OPT_i_Group
);
2252 for (InputInfoList::const_iterator
2253 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2254 const InputInfo
&II
= *it
;
2256 CmdArgs
.push_back(II
.getFilename());
2259 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wp_COMMA
,
2260 options::OPT_Xpreprocessor
);
2262 if (Args
.hasArg(options::OPT_fmudflap
)) {
2263 CmdArgs
.push_back("-D_MUDFLAP");
2264 CmdArgs
.push_back("-include");
2265 CmdArgs
.push_back("mf-runtime.h");
2268 if (Args
.hasArg(options::OPT_fmudflapth
)) {
2269 CmdArgs
.push_back("-D_MUDFLAP");
2270 CmdArgs
.push_back("-D_MUDFLAPTH");
2271 CmdArgs
.push_back("-include");
2272 CmdArgs
.push_back("mf-runtime.h");
2276 void darwin::CC1::AddCPPArgs(const ArgList
&Args
,
2277 ArgStringList
&CmdArgs
) const {
2278 // Derived from cpp spec.
2280 if (Args
.hasArg(options::OPT_static
)) {
2281 // The gcc spec is broken here, it refers to dynamic but
2282 // that has been translated. Start by being bug compatible.
2284 // if (!Args.hasArg(arglist.parser.dynamicOption))
2285 CmdArgs
.push_back("-D__STATIC__");
2287 CmdArgs
.push_back("-D__DYNAMIC__");
2289 if (Args
.hasArg(options::OPT_pthread
))
2290 CmdArgs
.push_back("-D_REENTRANT");
2293 void darwin::Preprocess::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2294 const InputInfo
&Output
,
2295 const InputInfoList
&Inputs
,
2296 const ArgList
&Args
,
2297 const char *LinkingOutput
) const {
2298 ArgStringList CmdArgs
;
2300 assert(Inputs
.size() == 1 && "Unexpected number of inputs!");
2302 CmdArgs
.push_back("-E");
2304 if (Args
.hasArg(options::OPT_traditional
) ||
2305 Args
.hasArg(options::OPT_traditional_cpp
))
2306 CmdArgs
.push_back("-traditional-cpp");
2308 ArgStringList OutputArgs
;
2309 assert(Output
.isFilename() && "Unexpected CC1 output.");
2310 OutputArgs
.push_back("-o");
2311 OutputArgs
.push_back(Output
.getFilename());
2313 if (Args
.hasArg(options::OPT_E
)) {
2314 AddCPPOptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2316 AddCPPOptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2317 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2320 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Group
);
2322 const char *CC1Name
= getCC1Name(Inputs
[0].getType());
2324 Args
.MakeArgString(getToolChain().GetProgramPath(CC1Name
));
2325 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2328 void darwin::Compile::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2329 const InputInfo
&Output
,
2330 const InputInfoList
&Inputs
,
2331 const ArgList
&Args
,
2332 const char *LinkingOutput
) const {
2333 const Driver
&D
= getToolChain().getDriver();
2334 ArgStringList CmdArgs
;
2336 assert(Inputs
.size() == 1 && "Unexpected number of inputs!");
2338 types::ID InputType
= Inputs
[0].getType();
2340 if ((A
= Args
.getLastArg(options::OPT_traditional
)))
2341 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
2342 << A
->getAsString(Args
) << "-E";
2344 if (JA
.getType() == types::TY_LLVM_IR
||
2345 JA
.getType() == types::TY_LTO_IR
)
2346 CmdArgs
.push_back("-emit-llvm");
2347 else if (JA
.getType() == types::TY_LLVM_BC
||
2348 JA
.getType() == types::TY_LTO_BC
)
2349 CmdArgs
.push_back("-emit-llvm-bc");
2350 else if (Output
.getType() == types::TY_AST
)
2351 D
.Diag(clang::diag::err_drv_no_ast_support
)
2352 << getToolChain().getTripleString();
2353 else if (JA
.getType() != types::TY_PP_Asm
&&
2354 JA
.getType() != types::TY_PCH
)
2355 D
.Diag(clang::diag::err_drv_invalid_gcc_output_type
)
2356 << getTypeName(JA
.getType());
2358 ArgStringList OutputArgs
;
2359 if (Output
.getType() != types::TY_PCH
) {
2360 OutputArgs
.push_back("-o");
2361 if (Output
.isNothing())
2362 OutputArgs
.push_back("/dev/null");
2364 OutputArgs
.push_back(Output
.getFilename());
2367 // There is no need for this level of compatibility, but it makes
2369 bool OutputArgsEarly
= (Args
.hasArg(options::OPT_fsyntax_only
) ||
2370 Args
.hasArg(options::OPT_S
));
2372 if (types::getPreprocessedType(InputType
) != types::TY_INVALID
) {
2373 AddCPPUniqueOptionsArgs(Args
, CmdArgs
, Inputs
);
2374 if (OutputArgsEarly
) {
2375 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2377 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2378 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2381 CmdArgs
.push_back("-fpreprocessed");
2383 for (InputInfoList::const_iterator
2384 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2385 const InputInfo
&II
= *it
;
2387 // Reject AST inputs.
2388 if (II
.getType() == types::TY_AST
) {
2389 D
.Diag(clang::diag::err_drv_no_ast_support
)
2390 << getToolChain().getTripleString();
2394 CmdArgs
.push_back(II
.getFilename());
2397 if (OutputArgsEarly
) {
2398 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2400 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2401 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2405 if (Output
.getType() == types::TY_PCH
) {
2406 assert(Output
.isFilename() && "Invalid PCH output.");
2408 CmdArgs
.push_back("-o");
2409 // NOTE: gcc uses a temp .s file for this, but there doesn't seem
2410 // to be a good reason.
2411 CmdArgs
.push_back("/dev/null");
2413 CmdArgs
.push_back("--output-pch=");
2414 CmdArgs
.push_back(Output
.getFilename());
2417 const char *CC1Name
= getCC1Name(Inputs
[0].getType());
2419 Args
.MakeArgString(getToolChain().GetProgramPath(CC1Name
));
2420 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2423 void darwin::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2424 const InputInfo
&Output
,
2425 const InputInfoList
&Inputs
,
2426 const ArgList
&Args
,
2427 const char *LinkingOutput
) const {
2428 ArgStringList CmdArgs
;
2430 assert(Inputs
.size() == 1 && "Unexpected number of inputs.");
2431 const InputInfo
&Input
= Inputs
[0];
2433 // Bit of a hack, this is only used for original inputs.
2435 // FIXME: This is broken for preprocessed .s inputs.
2436 if (Input
.isFilename() &&
2437 strcmp(Input
.getFilename(), Input
.getBaseInput()) == 0) {
2438 if (Args
.hasArg(options::OPT_gstabs
))
2439 CmdArgs
.push_back("--gstabs");
2440 else if (Args
.hasArg(options::OPT_g_Group
))
2441 CmdArgs
.push_back("--gdwarf2");
2444 // Derived from asm spec.
2445 AddDarwinArch(Args
, CmdArgs
);
2447 // Use -force_cpusubtype_ALL on x86 by default.
2448 if (getToolChain().getTriple().getArch() == llvm::Triple::x86
||
2449 getToolChain().getTriple().getArch() == llvm::Triple::x86_64
||
2450 Args
.hasArg(options::OPT_force__cpusubtype__ALL
))
2451 CmdArgs
.push_back("-force_cpusubtype_ALL");
2453 if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64
&&
2454 (Args
.hasArg(options::OPT_mkernel
) ||
2455 Args
.hasArg(options::OPT_static
) ||
2456 Args
.hasArg(options::OPT_fapple_kext
)))
2457 CmdArgs
.push_back("-static");
2459 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2460 options::OPT_Xassembler
);
2462 assert(Output
.isFilename() && "Unexpected lipo output.");
2463 CmdArgs
.push_back("-o");
2464 CmdArgs
.push_back(Output
.getFilename());
2466 assert(Input
.isFilename() && "Invalid input.");
2467 CmdArgs
.push_back(Input
.getFilename());
2469 // asm_final spec is empty.
2472 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
2473 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2476 void darwin::DarwinTool::AddDarwinArch(const ArgList
&Args
,
2477 ArgStringList
&CmdArgs
) const {
2478 llvm::StringRef ArchName
= getDarwinToolChain().getDarwinArchName(Args
);
2480 // Derived from darwin_arch spec.
2481 CmdArgs
.push_back("-arch");
2482 CmdArgs
.push_back(Args
.MakeArgString(ArchName
));
2484 // FIXME: Is this needed anymore?
2485 if (ArchName
== "arm")
2486 CmdArgs
.push_back("-force_cpusubtype_ALL");
2489 void darwin::Link::AddLinkArgs(Compilation
&C
,
2490 const ArgList
&Args
,
2491 ArgStringList
&CmdArgs
) const {
2492 const Driver
&D
= getToolChain().getDriver();
2494 unsigned Version
[3] = { 0, 0, 0 };
2495 if (Arg
*A
= Args
.getLastArg(options::OPT_mlinker_version_EQ
)) {
2497 if (!Driver::GetReleaseVersion(A
->getValue(Args
), Version
[0],
2498 Version
[1], Version
[2], HadExtra
) ||
2500 D
.Diag(clang::diag::err_drv_invalid_version_number
)
2501 << A
->getAsString(Args
);
2504 // Newer linkers support -demangle, pass it if supported and not disabled by
2507 // FIXME: We temporarily avoid passing -demangle to any iOS linker, because
2508 // unfortunately we can't be guaranteed that the linker version used there
2509 // will match the linker version detected at configure time. We need the
2510 // universal driver.
2511 if (Version
[0] >= 100 && !Args
.hasArg(options::OPT_Z_Xlinker__no_demangle
) &&
2512 !getDarwinToolChain().isTargetIPhoneOS()) {
2513 // Don't pass -demangle to ld_classic.
2515 // FIXME: This is a temporary workaround, ld should be handling this.
2516 bool UsesLdClassic
= (getToolChain().getArch() == llvm::Triple::x86
&&
2517 Args
.hasArg(options::OPT_static
));
2518 if (getToolChain().getArch() == llvm::Triple::x86
) {
2519 for (arg_iterator it
= Args
.filtered_begin(options::OPT_Xlinker
,
2520 options::OPT_Wl_COMMA
),
2521 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
2523 for (unsigned i
= 0, e
= A
->getNumValues(); i
!= e
; ++i
)
2524 if (llvm::StringRef(A
->getValue(Args
, i
)) == "-kext")
2525 UsesLdClassic
= true;
2529 CmdArgs
.push_back("-demangle");
2532 // Derived from the "link" spec.
2533 Args
.AddAllArgs(CmdArgs
, options::OPT_static
);
2534 if (!Args
.hasArg(options::OPT_static
))
2535 CmdArgs
.push_back("-dynamic");
2536 if (Args
.hasArg(options::OPT_fgnu_runtime
)) {
2537 // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu
2538 // here. How do we wish to handle such things?
2541 if (!Args
.hasArg(options::OPT_dynamiclib
)) {
2542 AddDarwinArch(Args
, CmdArgs
);
2543 // FIXME: Why do this only on this path?
2544 Args
.AddLastArg(CmdArgs
, options::OPT_force__cpusubtype__ALL
);
2546 Args
.AddLastArg(CmdArgs
, options::OPT_bundle
);
2547 Args
.AddAllArgs(CmdArgs
, options::OPT_bundle__loader
);
2548 Args
.AddAllArgs(CmdArgs
, options::OPT_client__name
);
2551 if ((A
= Args
.getLastArg(options::OPT_compatibility__version
)) ||
2552 (A
= Args
.getLastArg(options::OPT_current__version
)) ||
2553 (A
= Args
.getLastArg(options::OPT_install__name
)))
2554 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
2555 << A
->getAsString(Args
) << "-dynamiclib";
2557 Args
.AddLastArg(CmdArgs
, options::OPT_force__flat__namespace
);
2558 Args
.AddLastArg(CmdArgs
, options::OPT_keep__private__externs
);
2559 Args
.AddLastArg(CmdArgs
, options::OPT_private__bundle
);
2561 CmdArgs
.push_back("-dylib");
2564 if ((A
= Args
.getLastArg(options::OPT_bundle
)) ||
2565 (A
= Args
.getLastArg(options::OPT_bundle__loader
)) ||
2566 (A
= Args
.getLastArg(options::OPT_client__name
)) ||
2567 (A
= Args
.getLastArg(options::OPT_force__flat__namespace
)) ||
2568 (A
= Args
.getLastArg(options::OPT_keep__private__externs
)) ||
2569 (A
= Args
.getLastArg(options::OPT_private__bundle
)))
2570 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
2571 << A
->getAsString(Args
) << "-dynamiclib";
2573 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_compatibility__version
,
2574 "-dylib_compatibility_version");
2575 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_current__version
,
2576 "-dylib_current_version");
2578 AddDarwinArch(Args
, CmdArgs
);
2580 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_install__name
,
2581 "-dylib_install_name");
2584 Args
.AddLastArg(CmdArgs
, options::OPT_all__load
);
2585 Args
.AddAllArgs(CmdArgs
, options::OPT_allowable__client
);
2586 Args
.AddLastArg(CmdArgs
, options::OPT_bind__at__load
);
2587 if (getDarwinToolChain().isTargetIPhoneOS())
2588 Args
.AddLastArg(CmdArgs
, options::OPT_arch__errors__fatal
);
2589 Args
.AddLastArg(CmdArgs
, options::OPT_dead__strip
);
2590 Args
.AddLastArg(CmdArgs
, options::OPT_no__dead__strip__inits__and__terms
);
2591 Args
.AddAllArgs(CmdArgs
, options::OPT_dylib__file
);
2592 Args
.AddLastArg(CmdArgs
, options::OPT_dynamic
);
2593 Args
.AddAllArgs(CmdArgs
, options::OPT_exported__symbols__list
);
2594 Args
.AddLastArg(CmdArgs
, options::OPT_flat__namespace
);
2595 Args
.AddAllArgs(CmdArgs
, options::OPT_headerpad__max__install__names
);
2596 Args
.AddAllArgs(CmdArgs
, options::OPT_image__base
);
2597 Args
.AddAllArgs(CmdArgs
, options::OPT_init
);
2599 // Adding all arguments doesn't make sense here but this is what gcc does. One
2600 // of this should always be present thanks to argument translation.
2601 assert((Args
.hasArg(options::OPT_mmacosx_version_min_EQ
) ||
2602 Args
.hasArg(options::OPT_miphoneos_version_min_EQ
)) &&
2603 "Missing version argument (lost in translation)?");
2604 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_mmacosx_version_min_EQ
,
2605 "-macosx_version_min");
2606 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_miphoneos_version_min_EQ
,
2607 "-iphoneos_version_min");
2608 Args
.AddLastArg(CmdArgs
, options::OPT_nomultidefs
);
2609 Args
.AddLastArg(CmdArgs
, options::OPT_multi__module
);
2610 Args
.AddLastArg(CmdArgs
, options::OPT_single__module
);
2611 Args
.AddAllArgs(CmdArgs
, options::OPT_multiply__defined
);
2612 Args
.AddAllArgs(CmdArgs
, options::OPT_multiply__defined__unused
);
2614 if (const Arg
*A
= Args
.getLastArg(options::OPT_fpie
, options::OPT_fPIE
,
2615 options::OPT_fno_pie
,
2616 options::OPT_fno_PIE
)) {
2617 if (A
->getOption().matches(options::OPT_fpie
) ||
2618 A
->getOption().matches(options::OPT_fPIE
))
2619 CmdArgs
.push_back("-pie");
2621 CmdArgs
.push_back("-no_pie");
2624 Args
.AddLastArg(CmdArgs
, options::OPT_prebind
);
2625 Args
.AddLastArg(CmdArgs
, options::OPT_noprebind
);
2626 Args
.AddLastArg(CmdArgs
, options::OPT_nofixprebinding
);
2627 Args
.AddLastArg(CmdArgs
, options::OPT_prebind__all__twolevel__modules
);
2628 Args
.AddLastArg(CmdArgs
, options::OPT_read__only__relocs
);
2629 Args
.AddAllArgs(CmdArgs
, options::OPT_sectcreate
);
2630 Args
.AddAllArgs(CmdArgs
, options::OPT_sectorder
);
2631 Args
.AddAllArgs(CmdArgs
, options::OPT_seg1addr
);
2632 Args
.AddAllArgs(CmdArgs
, options::OPT_segprot
);
2633 Args
.AddAllArgs(CmdArgs
, options::OPT_segaddr
);
2634 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__only__addr
);
2635 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__write__addr
);
2636 Args
.AddAllArgs(CmdArgs
, options::OPT_seg__addr__table
);
2637 Args
.AddAllArgs(CmdArgs
, options::OPT_seg__addr__table__filename
);
2638 Args
.AddAllArgs(CmdArgs
, options::OPT_sub__library
);
2639 Args
.AddAllArgs(CmdArgs
, options::OPT_sub__umbrella
);
2641 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_isysroot
, "-syslibroot");
2642 if (getDarwinToolChain().isTargetIPhoneOS()) {
2643 if (!Args
.hasArg(options::OPT_isysroot
)) {
2644 CmdArgs
.push_back("-syslibroot");
2645 CmdArgs
.push_back("/Developer/SDKs/Extra");
2649 Args
.AddLastArg(CmdArgs
, options::OPT_twolevel__namespace
);
2650 Args
.AddLastArg(CmdArgs
, options::OPT_twolevel__namespace__hints
);
2651 Args
.AddAllArgs(CmdArgs
, options::OPT_umbrella
);
2652 Args
.AddAllArgs(CmdArgs
, options::OPT_undefined
);
2653 Args
.AddAllArgs(CmdArgs
, options::OPT_unexported__symbols__list
);
2654 Args
.AddAllArgs(CmdArgs
, options::OPT_weak__reference__mismatches
);
2655 Args
.AddLastArg(CmdArgs
, options::OPT_X_Flag
);
2656 Args
.AddAllArgs(CmdArgs
, options::OPT_y
);
2657 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2658 Args
.AddAllArgs(CmdArgs
, options::OPT_pagezero__size
);
2659 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__
);
2660 Args
.AddLastArg(CmdArgs
, options::OPT_seglinkedit
);
2661 Args
.AddLastArg(CmdArgs
, options::OPT_noseglinkedit
);
2662 Args
.AddAllArgs(CmdArgs
, options::OPT_sectalign
);
2663 Args
.AddAllArgs(CmdArgs
, options::OPT_sectobjectsymbols
);
2664 Args
.AddAllArgs(CmdArgs
, options::OPT_segcreate
);
2665 Args
.AddLastArg(CmdArgs
, options::OPT_whyload
);
2666 Args
.AddLastArg(CmdArgs
, options::OPT_whatsloaded
);
2667 Args
.AddAllArgs(CmdArgs
, options::OPT_dylinker__install__name
);
2668 Args
.AddLastArg(CmdArgs
, options::OPT_dylinker
);
2669 Args
.AddLastArg(CmdArgs
, options::OPT_Mach
);
2672 void darwin::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2673 const InputInfo
&Output
,
2674 const InputInfoList
&Inputs
,
2675 const ArgList
&Args
,
2676 const char *LinkingOutput
) const {
2677 assert(Output
.getType() == types::TY_Image
&& "Invalid linker output type.");
2679 // The logic here is derived from gcc's behavior; most of which
2680 // comes from specs (starting with link_command). Consult gcc for
2681 // more information.
2682 ArgStringList CmdArgs
;
2684 // I'm not sure why this particular decomposition exists in gcc, but
2685 // we follow suite for ease of comparison.
2686 AddLinkArgs(C
, Args
, CmdArgs
);
2688 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Flag
);
2689 Args
.AddAllArgs(CmdArgs
, options::OPT_s
);
2690 Args
.AddAllArgs(CmdArgs
, options::OPT_t
);
2691 Args
.AddAllArgs(CmdArgs
, options::OPT_Z_Flag
);
2692 Args
.AddAllArgs(CmdArgs
, options::OPT_u_Group
);
2693 Args
.AddAllArgs(CmdArgs
, options::OPT_A
);
2694 Args
.AddLastArg(CmdArgs
, options::OPT_e
);
2695 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Separate
);
2696 Args
.AddAllArgs(CmdArgs
, options::OPT_r
);
2698 // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading
2699 // members of static archive libraries which implement Objective-C classes or
2701 if (Args
.hasArg(options::OPT_ObjC
) || Args
.hasArg(options::OPT_ObjCXX
))
2702 CmdArgs
.push_back("-ObjC");
2704 CmdArgs
.push_back("-o");
2705 CmdArgs
.push_back(Output
.getFilename());
2707 if (!Args
.hasArg(options::OPT_A
) &&
2708 !Args
.hasArg(options::OPT_nostdlib
) &&
2709 !Args
.hasArg(options::OPT_nostartfiles
)) {
2710 // Derived from startfile spec.
2711 if (Args
.hasArg(options::OPT_dynamiclib
)) {
2712 // Derived from darwin_dylib1 spec.
2713 if (getDarwinToolChain().isTargetIPhoneOS()) {
2714 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2715 CmdArgs
.push_back("-ldylib1.o");
2717 if (getDarwinToolChain().isMacosxVersionLT(10, 5))
2718 CmdArgs
.push_back("-ldylib1.o");
2719 else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2720 CmdArgs
.push_back("-ldylib1.10.5.o");
2723 if (Args
.hasArg(options::OPT_bundle
)) {
2724 if (!Args
.hasArg(options::OPT_static
)) {
2725 // Derived from darwin_bundle1 spec.
2726 if (getDarwinToolChain().isTargetIPhoneOS()) {
2727 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2728 CmdArgs
.push_back("-lbundle1.o");
2730 if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2731 CmdArgs
.push_back("-lbundle1.o");
2735 if (Args
.hasArg(options::OPT_pg
)) {
2736 if (Args
.hasArg(options::OPT_static
) ||
2737 Args
.hasArg(options::OPT_object
) ||
2738 Args
.hasArg(options::OPT_preload
)) {
2739 CmdArgs
.push_back("-lgcrt0.o");
2741 CmdArgs
.push_back("-lgcrt1.o");
2743 // darwin_crt2 spec is empty.
2746 if (Args
.hasArg(options::OPT_static
) ||
2747 Args
.hasArg(options::OPT_object
) ||
2748 Args
.hasArg(options::OPT_preload
)) {
2749 CmdArgs
.push_back("-lcrt0.o");
2751 // Derived from darwin_crt1 spec.
2752 if (getDarwinToolChain().isTargetIPhoneOS()) {
2753 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2754 CmdArgs
.push_back("-lcrt1.o");
2756 CmdArgs
.push_back("-lcrt1.3.1.o");
2758 if (getDarwinToolChain().isMacosxVersionLT(10, 5))
2759 CmdArgs
.push_back("-lcrt1.o");
2760 else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2761 CmdArgs
.push_back("-lcrt1.10.5.o");
2763 CmdArgs
.push_back("-lcrt1.10.6.o");
2765 // darwin_crt2 spec is empty.
2772 if (!getDarwinToolChain().isTargetIPhoneOS() &&
2773 Args
.hasArg(options::OPT_shared_libgcc
) &&
2774 getDarwinToolChain().isMacosxVersionLT(10, 5)) {
2776 Args
.MakeArgString(getToolChain().GetFilePath("crt3.o"));
2777 CmdArgs
.push_back(Str
);
2781 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
2783 if (Args
.hasArg(options::OPT_fopenmp
))
2784 // This is more complicated in gcc...
2785 CmdArgs
.push_back("-lgomp");
2787 getDarwinToolChain().AddLinkSearchPathArgs(Args
, CmdArgs
);
2789 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
2791 if (LinkingOutput
) {
2792 CmdArgs
.push_back("-arch_multiple");
2793 CmdArgs
.push_back("-final_output");
2794 CmdArgs
.push_back(LinkingOutput
);
2797 if (Args
.hasArg(options::OPT_fprofile_arcs
) ||
2798 Args
.hasArg(options::OPT_fprofile_generate
) ||
2799 Args
.hasArg(options::OPT_fcreate_profile
) ||
2800 Args
.hasArg(options::OPT_coverage
))
2801 CmdArgs
.push_back("-lgcov");
2803 if (Args
.hasArg(options::OPT_fnested_functions
))
2804 CmdArgs
.push_back("-allow_stack_execute");
2806 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2807 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
2808 if (getToolChain().getDriver().CCCIsCXX
)
2809 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
2811 // link_ssp spec is empty.
2813 // Let the tool chain choose which runtime library to link.
2814 getDarwinToolChain().AddLinkRuntimeLibArgs(Args
, CmdArgs
);
2817 if (!Args
.hasArg(options::OPT_A
) &&
2818 !Args
.hasArg(options::OPT_nostdlib
) &&
2819 !Args
.hasArg(options::OPT_nostartfiles
)) {
2820 // endfile_spec is empty.
2823 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
2824 Args
.AddAllArgs(CmdArgs
, options::OPT_F
);
2827 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
2828 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2831 void darwin::Lipo::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2832 const InputInfo
&Output
,
2833 const InputInfoList
&Inputs
,
2834 const ArgList
&Args
,
2835 const char *LinkingOutput
) const {
2836 ArgStringList CmdArgs
;
2838 CmdArgs
.push_back("-create");
2839 assert(Output
.isFilename() && "Unexpected lipo output.");
2841 CmdArgs
.push_back("-output");
2842 CmdArgs
.push_back(Output
.getFilename());
2844 for (InputInfoList::const_iterator
2845 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2846 const InputInfo
&II
= *it
;
2847 assert(II
.isFilename() && "Unexpected lipo input.");
2848 CmdArgs
.push_back(II
.getFilename());
2851 Args
.MakeArgString(getToolChain().GetProgramPath("lipo"));
2852 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2855 void darwin::Dsymutil::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2856 const InputInfo
&Output
,
2857 const InputInfoList
&Inputs
,
2858 const ArgList
&Args
,
2859 const char *LinkingOutput
) const {
2860 ArgStringList CmdArgs
;
2862 assert(Inputs
.size() == 1 && "Unable to handle multiple inputs.");
2863 const InputInfo
&Input
= Inputs
[0];
2864 assert(Input
.isFilename() && "Unexpected dsymutil input.");
2865 CmdArgs
.push_back(Input
.getFilename());
2867 CmdArgs
.push_back("-o");
2868 CmdArgs
.push_back(Output
.getFilename());
2871 Args
.MakeArgString(getToolChain().GetProgramPath("dsymutil"));
2872 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2875 void auroraux::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2876 const InputInfo
&Output
,
2877 const InputInfoList
&Inputs
,
2878 const ArgList
&Args
,
2879 const char *LinkingOutput
) const {
2880 ArgStringList CmdArgs
;
2882 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2883 options::OPT_Xassembler
);
2885 CmdArgs
.push_back("-o");
2886 CmdArgs
.push_back(Output
.getFilename());
2888 for (InputInfoList::const_iterator
2889 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2890 const InputInfo
&II
= *it
;
2891 CmdArgs
.push_back(II
.getFilename());
2895 Args
.MakeArgString(getToolChain().GetProgramPath("gas"));
2896 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2899 void auroraux::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2900 const InputInfo
&Output
,
2901 const InputInfoList
&Inputs
,
2902 const ArgList
&Args
,
2903 const char *LinkingOutput
) const {
2904 ArgStringList CmdArgs
;
2906 if ((!Args
.hasArg(options::OPT_nostdlib
)) &&
2907 (!Args
.hasArg(options::OPT_shared
))) {
2908 CmdArgs
.push_back("-e");
2909 CmdArgs
.push_back("_start");
2912 if (Args
.hasArg(options::OPT_static
)) {
2913 CmdArgs
.push_back("-Bstatic");
2914 CmdArgs
.push_back("-dn");
2916 // CmdArgs.push_back("--eh-frame-hdr");
2917 CmdArgs
.push_back("-Bdynamic");
2918 if (Args
.hasArg(options::OPT_shared
)) {
2919 CmdArgs
.push_back("-shared");
2921 CmdArgs
.push_back("--dynamic-linker");
2922 CmdArgs
.push_back("/lib/ld.so.1"); // 64Bit Path /lib/amd64/ld.so.1
2926 if (Output
.isFilename()) {
2927 CmdArgs
.push_back("-o");
2928 CmdArgs
.push_back(Output
.getFilename());
2930 assert(Output
.isNothing() && "Invalid output.");
2933 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2934 !Args
.hasArg(options::OPT_nostartfiles
)) {
2935 if (!Args
.hasArg(options::OPT_shared
)) {
2936 CmdArgs
.push_back(Args
.MakeArgString(
2937 getToolChain().GetFilePath("crt1.o")));
2938 CmdArgs
.push_back(Args
.MakeArgString(
2939 getToolChain().GetFilePath("crti.o")));
2940 CmdArgs
.push_back(Args
.MakeArgString(
2941 getToolChain().GetFilePath("crtbegin.o")));
2943 CmdArgs
.push_back(Args
.MakeArgString(
2944 getToolChain().GetFilePath("crti.o")));
2946 CmdArgs
.push_back(Args
.MakeArgString(
2947 getToolChain().GetFilePath("crtn.o")));
2950 CmdArgs
.push_back(Args
.MakeArgString("-L/opt/gcc4/lib/gcc/"
2951 + getToolChain().getTripleString()
2954 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
2955 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
2956 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
2958 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
2960 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2961 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
2962 // FIXME: For some reason GCC passes -lgcc before adding
2963 // the default system libraries. Just mimic this for now.
2964 CmdArgs
.push_back("-lgcc");
2966 if (Args
.hasArg(options::OPT_pthread
))
2967 CmdArgs
.push_back("-pthread");
2968 if (!Args
.hasArg(options::OPT_shared
))
2969 CmdArgs
.push_back("-lc");
2970 CmdArgs
.push_back("-lgcc");
2973 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2974 !Args
.hasArg(options::OPT_nostartfiles
)) {
2975 if (!Args
.hasArg(options::OPT_shared
))
2976 CmdArgs
.push_back(Args
.MakeArgString(
2977 getToolChain().GetFilePath("crtend.o")));
2981 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
2982 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2985 void openbsd::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2986 const InputInfo
&Output
,
2987 const InputInfoList
&Inputs
,
2988 const ArgList
&Args
,
2989 const char *LinkingOutput
) const {
2990 ArgStringList CmdArgs
;
2992 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2993 options::OPT_Xassembler
);
2995 CmdArgs
.push_back("-o");
2996 CmdArgs
.push_back(Output
.getFilename());
2998 for (InputInfoList::const_iterator
2999 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3000 const InputInfo
&II
= *it
;
3001 CmdArgs
.push_back(II
.getFilename());
3005 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3006 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3009 void openbsd::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3010 const InputInfo
&Output
,
3011 const InputInfoList
&Inputs
,
3012 const ArgList
&Args
,
3013 const char *LinkingOutput
) const {
3014 const Driver
&D
= getToolChain().getDriver();
3015 ArgStringList CmdArgs
;
3017 if ((!Args
.hasArg(options::OPT_nostdlib
)) &&
3018 (!Args
.hasArg(options::OPT_shared
))) {
3019 CmdArgs
.push_back("-e");
3020 CmdArgs
.push_back("__start");
3023 if (Args
.hasArg(options::OPT_static
)) {
3024 CmdArgs
.push_back("-Bstatic");
3026 if (Args
.hasArg(options::OPT_rdynamic
))
3027 CmdArgs
.push_back("-export-dynamic");
3028 CmdArgs
.push_back("--eh-frame-hdr");
3029 CmdArgs
.push_back("-Bdynamic");
3030 if (Args
.hasArg(options::OPT_shared
)) {
3031 CmdArgs
.push_back("-shared");
3033 CmdArgs
.push_back("-dynamic-linker");
3034 CmdArgs
.push_back("/usr/libexec/ld.so");
3038 if (Output
.isFilename()) {
3039 CmdArgs
.push_back("-o");
3040 CmdArgs
.push_back(Output
.getFilename());
3042 assert(Output
.isNothing() && "Invalid output.");
3045 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3046 !Args
.hasArg(options::OPT_nostartfiles
)) {
3047 if (!Args
.hasArg(options::OPT_shared
)) {
3048 CmdArgs
.push_back(Args
.MakeArgString(
3049 getToolChain().GetFilePath("crt0.o")));
3050 CmdArgs
.push_back(Args
.MakeArgString(
3051 getToolChain().GetFilePath("crtbegin.o")));
3053 CmdArgs
.push_back(Args
.MakeArgString(
3054 getToolChain().GetFilePath("crtbeginS.o")));
3058 std::string Triple
= getToolChain().getTripleString();
3059 if (Triple
.substr(0, 6) == "x86_64")
3060 Triple
.replace(0, 6, "amd64");
3061 CmdArgs
.push_back(Args
.MakeArgString("-L/usr/lib/gcc-lib/" + Triple
+
3064 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3065 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3066 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3068 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3070 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3071 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3073 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3074 CmdArgs
.push_back("-lm");
3077 // FIXME: For some reason GCC passes -lgcc before adding
3078 // the default system libraries. Just mimic this for now.
3079 CmdArgs
.push_back("-lgcc");
3081 if (Args
.hasArg(options::OPT_pthread
))
3082 CmdArgs
.push_back("-pthread");
3083 if (!Args
.hasArg(options::OPT_shared
))
3084 CmdArgs
.push_back("-lc");
3085 CmdArgs
.push_back("-lgcc");
3088 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3089 !Args
.hasArg(options::OPT_nostartfiles
)) {
3090 if (!Args
.hasArg(options::OPT_shared
))
3091 CmdArgs
.push_back(Args
.MakeArgString(
3092 getToolChain().GetFilePath("crtend.o")));
3094 CmdArgs
.push_back(Args
.MakeArgString(
3095 getToolChain().GetFilePath("crtendS.o")));
3099 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3100 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3103 void freebsd::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3104 const InputInfo
&Output
,
3105 const InputInfoList
&Inputs
,
3106 const ArgList
&Args
,
3107 const char *LinkingOutput
) const {
3108 ArgStringList CmdArgs
;
3110 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
3111 // instruct as in the base system to assemble 32-bit code.
3112 if (getToolChain().getArchName() == "i386")
3113 CmdArgs
.push_back("--32");
3116 // Set byte order explicitly
3117 if (getToolChain().getArchName() == "mips")
3118 CmdArgs
.push_back("-EB");
3119 else if (getToolChain().getArchName() == "mipsel")
3120 CmdArgs
.push_back("-EL");
3122 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3123 options::OPT_Xassembler
);
3125 CmdArgs
.push_back("-o");
3126 CmdArgs
.push_back(Output
.getFilename());
3128 for (InputInfoList::const_iterator
3129 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3130 const InputInfo
&II
= *it
;
3131 CmdArgs
.push_back(II
.getFilename());
3135 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3136 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3139 void freebsd::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3140 const InputInfo
&Output
,
3141 const InputInfoList
&Inputs
,
3142 const ArgList
&Args
,
3143 const char *LinkingOutput
) const {
3144 const Driver
&D
= getToolChain().getDriver();
3145 ArgStringList CmdArgs
;
3147 if (Args
.hasArg(options::OPT_static
)) {
3148 CmdArgs
.push_back("-Bstatic");
3150 if (Args
.hasArg(options::OPT_rdynamic
))
3151 CmdArgs
.push_back("-export-dynamic");
3152 CmdArgs
.push_back("--eh-frame-hdr");
3153 if (Args
.hasArg(options::OPT_shared
)) {
3154 CmdArgs
.push_back("-Bshareable");
3156 CmdArgs
.push_back("-dynamic-linker");
3157 CmdArgs
.push_back("/libexec/ld-elf.so.1");
3161 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
3162 // instruct ld in the base system to link 32-bit code.
3163 if (getToolChain().getArchName() == "i386") {
3164 CmdArgs
.push_back("-m");
3165 CmdArgs
.push_back("elf_i386_fbsd");
3168 if (Output
.isFilename()) {
3169 CmdArgs
.push_back("-o");
3170 CmdArgs
.push_back(Output
.getFilename());
3172 assert(Output
.isNothing() && "Invalid output.");
3175 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3176 !Args
.hasArg(options::OPT_nostartfiles
)) {
3177 if (!Args
.hasArg(options::OPT_shared
)) {
3178 if (Args
.hasArg(options::OPT_pg
))
3179 CmdArgs
.push_back(Args
.MakeArgString(
3180 getToolChain().GetFilePath("gcrt1.o")));
3182 CmdArgs
.push_back(Args
.MakeArgString(
3183 getToolChain().GetFilePath("crt1.o")));
3184 CmdArgs
.push_back(Args
.MakeArgString(
3185 getToolChain().GetFilePath("crti.o")));
3186 CmdArgs
.push_back(Args
.MakeArgString(
3187 getToolChain().GetFilePath("crtbegin.o")));
3189 CmdArgs
.push_back(Args
.MakeArgString(
3190 getToolChain().GetFilePath("crti.o")));
3191 CmdArgs
.push_back(Args
.MakeArgString(
3192 getToolChain().GetFilePath("crtbeginS.o")));
3196 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3197 CmdArgs
.push_back("-L/usr/lib");
3198 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3199 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3200 Args
.AddAllArgs(CmdArgs
, options::OPT_s
);
3201 Args
.AddAllArgs(CmdArgs
, options::OPT_t
);
3202 Args
.AddAllArgs(CmdArgs
, options::OPT_Z_Flag
);
3203 Args
.AddAllArgs(CmdArgs
, options::OPT_r
);
3205 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3207 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3208 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3210 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3211 if (Args
.hasArg(options::OPT_pg
))
3212 CmdArgs
.push_back("-lm_p");
3214 CmdArgs
.push_back("-lm");
3216 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
3217 // the default system libraries. Just mimic this for now.
3218 if (Args
.hasArg(options::OPT_pg
))
3219 CmdArgs
.push_back("-lgcc_p");
3221 CmdArgs
.push_back("-lgcc");
3222 if (Args
.hasArg(options::OPT_static
)) {
3223 CmdArgs
.push_back("-lgcc_eh");
3224 } else if (Args
.hasArg(options::OPT_pg
)) {
3225 CmdArgs
.push_back("-lgcc_eh_p");
3227 CmdArgs
.push_back("--as-needed");
3228 CmdArgs
.push_back("-lgcc_s");
3229 CmdArgs
.push_back("--no-as-needed");
3232 if (Args
.hasArg(options::OPT_pthread
)) {
3233 if (Args
.hasArg(options::OPT_pg
))
3234 CmdArgs
.push_back("-lpthread_p");
3236 CmdArgs
.push_back("-lpthread");
3239 if (Args
.hasArg(options::OPT_pg
)) {
3240 if (Args
.hasArg(options::OPT_shared
))
3241 CmdArgs
.push_back("-lc");
3243 CmdArgs
.push_back("-lc_p");
3244 CmdArgs
.push_back("-lgcc_p");
3246 CmdArgs
.push_back("-lc");
3247 CmdArgs
.push_back("-lgcc");
3250 if (Args
.hasArg(options::OPT_static
)) {
3251 CmdArgs
.push_back("-lgcc_eh");
3252 } else if (Args
.hasArg(options::OPT_pg
)) {
3253 CmdArgs
.push_back("-lgcc_eh_p");
3255 CmdArgs
.push_back("--as-needed");
3256 CmdArgs
.push_back("-lgcc_s");
3257 CmdArgs
.push_back("--no-as-needed");
3261 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3262 !Args
.hasArg(options::OPT_nostartfiles
)) {
3263 if (!Args
.hasArg(options::OPT_shared
))
3264 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3267 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3269 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3274 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3275 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3278 void netbsd::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3279 const InputInfo
&Output
,
3280 const InputInfoList
&Inputs
,
3281 const ArgList
&Args
,
3282 const char *LinkingOutput
) const {
3283 ArgStringList CmdArgs
;
3285 // When building 32-bit code on NetBSD/amd64, we have to explicitly
3286 // instruct as in the base system to assemble 32-bit code.
3287 if (getToolChain().getArchName() == "i386")
3288 CmdArgs
.push_back("--32");
3291 // Set byte order explicitly
3292 if (getToolChain().getArchName() == "mips")
3293 CmdArgs
.push_back("-EB");
3294 else if (getToolChain().getArchName() == "mipsel")
3295 CmdArgs
.push_back("-EL");
3297 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3298 options::OPT_Xassembler
);
3300 CmdArgs
.push_back("-o");
3301 CmdArgs
.push_back(Output
.getFilename());
3303 for (InputInfoList::const_iterator
3304 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3305 const InputInfo
&II
= *it
;
3306 CmdArgs
.push_back(II
.getFilename());
3310 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3311 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3314 void netbsd::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3315 const InputInfo
&Output
,
3316 const InputInfoList
&Inputs
,
3317 const ArgList
&Args
,
3318 const char *LinkingOutput
) const {
3319 const Driver
&D
= getToolChain().getDriver();
3320 ArgStringList CmdArgs
;
3322 if (Args
.hasArg(options::OPT_static
)) {
3323 CmdArgs
.push_back("-Bstatic");
3325 if (Args
.hasArg(options::OPT_rdynamic
))
3326 CmdArgs
.push_back("-export-dynamic");
3327 CmdArgs
.push_back("--eh-frame-hdr");
3328 if (Args
.hasArg(options::OPT_shared
)) {
3329 CmdArgs
.push_back("-Bshareable");
3331 CmdArgs
.push_back("-dynamic-linker");
3332 CmdArgs
.push_back("/libexec/ld.elf_so");
3336 // When building 32-bit code on NetBSD/amd64, we have to explicitly
3337 // instruct ld in the base system to link 32-bit code.
3338 if (getToolChain().getArchName() == "i386") {
3339 CmdArgs
.push_back("-m");
3340 CmdArgs
.push_back("elf_i386");
3343 if (Output
.isFilename()) {
3344 CmdArgs
.push_back("-o");
3345 CmdArgs
.push_back(Output
.getFilename());
3347 assert(Output
.isNothing() && "Invalid output.");
3350 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3351 !Args
.hasArg(options::OPT_nostartfiles
)) {
3352 if (!Args
.hasArg(options::OPT_shared
)) {
3353 CmdArgs
.push_back(Args
.MakeArgString(
3354 getToolChain().GetFilePath("crt0.o")));
3355 CmdArgs
.push_back(Args
.MakeArgString(
3356 getToolChain().GetFilePath("crti.o")));
3357 CmdArgs
.push_back(Args
.MakeArgString(
3358 getToolChain().GetFilePath("crtbegin.o")));
3360 CmdArgs
.push_back(Args
.MakeArgString(
3361 getToolChain().GetFilePath("crti.o")));
3362 CmdArgs
.push_back(Args
.MakeArgString(
3363 getToolChain().GetFilePath("crtbeginS.o")));
3367 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3368 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3369 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3370 Args
.AddAllArgs(CmdArgs
, options::OPT_s
);
3371 Args
.AddAllArgs(CmdArgs
, options::OPT_t
);
3372 Args
.AddAllArgs(CmdArgs
, options::OPT_Z_Flag
);
3373 Args
.AddAllArgs(CmdArgs
, options::OPT_r
);
3375 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3377 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3378 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3380 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3381 CmdArgs
.push_back("-lm");
3383 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
3384 // the default system libraries. Just mimic this for now.
3385 CmdArgs
.push_back("-lgcc");
3386 if (Args
.hasArg(options::OPT_static
)) {
3387 CmdArgs
.push_back("-lgcc_eh");
3389 CmdArgs
.push_back("--as-needed");
3390 CmdArgs
.push_back("-lgcc_s");
3391 CmdArgs
.push_back("--no-as-needed");
3394 if (Args
.hasArg(options::OPT_pthread
))
3395 CmdArgs
.push_back("-lpthread");
3396 CmdArgs
.push_back("-lc");
3398 CmdArgs
.push_back("-lgcc");
3399 if (Args
.hasArg(options::OPT_static
)) {
3400 CmdArgs
.push_back("-lgcc_eh");
3402 CmdArgs
.push_back("--as-needed");
3403 CmdArgs
.push_back("-lgcc_s");
3404 CmdArgs
.push_back("--no-as-needed");
3408 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3409 !Args
.hasArg(options::OPT_nostartfiles
)) {
3410 if (!Args
.hasArg(options::OPT_shared
))
3411 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3414 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3416 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3421 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3422 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3425 void linuxtools::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3426 const InputInfo
&Output
,
3427 const InputInfoList
&Inputs
,
3428 const ArgList
&Args
,
3429 const char *LinkingOutput
) const {
3430 ArgStringList CmdArgs
;
3432 // Add --32/--64 to make sure we get the format we want.
3433 // This is incomplete
3434 if (getToolChain().getArch() == llvm::Triple::x86
) {
3435 CmdArgs
.push_back("--32");
3436 } else if (getToolChain().getArch() == llvm::Triple::x86_64
) {
3437 CmdArgs
.push_back("--64");
3438 } else if (getToolChain().getArch() == llvm::Triple::arm
) {
3439 llvm::StringRef MArch
= getToolChain().getArchName();
3440 if (MArch
== "armv7" || MArch
== "armv7a" || MArch
== "armv7-a")
3441 CmdArgs
.push_back("-mfpu=neon");
3444 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3445 options::OPT_Xassembler
);
3447 CmdArgs
.push_back("-o");
3448 CmdArgs
.push_back(Output
.getFilename());
3450 for (InputInfoList::const_iterator
3451 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3452 const InputInfo
&II
= *it
;
3453 CmdArgs
.push_back(II
.getFilename());
3457 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3458 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3461 void linuxtools::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3462 const InputInfo
&Output
,
3463 const InputInfoList
&Inputs
,
3464 const ArgList
&Args
,
3465 const char *LinkingOutput
) const {
3466 const toolchains::Linux
& ToolChain
=
3467 static_cast<const toolchains::Linux
&>(getToolChain());
3468 const Driver
&D
= ToolChain
.getDriver();
3469 ArgStringList CmdArgs
;
3471 // Silence warning for "clang -g foo.o -o foo"
3472 Args
.ClaimAllArgs(options::OPT_g_Group
);
3473 // and for "clang -g foo.o -o foo". Other warning options are already
3474 // handled somewhere else.
3475 Args
.ClaimAllArgs(options::OPT_w
);
3477 if (Arg
*A
= Args
.getLastArg(options::OPT__sysroot_EQ
)) {
3478 CmdArgs
.push_back("--sysroot");
3479 CmdArgs
.push_back(A
->getValue(Args
));
3482 if (Args
.hasArg(options::OPT_pie
))
3483 CmdArgs
.push_back("-pie");
3485 if (Args
.hasArg(options::OPT_rdynamic
))
3486 CmdArgs
.push_back("-export-dynamic");
3488 if (Args
.hasArg(options::OPT_s
))
3489 CmdArgs
.push_back("-s");
3491 for (std::vector
<std::string
>::const_iterator i
= ToolChain
.ExtraOpts
.begin(),
3492 e
= ToolChain
.ExtraOpts
.end();
3494 CmdArgs
.push_back(i
->c_str());
3496 if (!Args
.hasArg(options::OPT_static
)) {
3497 CmdArgs
.push_back("--eh-frame-hdr");
3500 CmdArgs
.push_back("-m");
3501 if (ToolChain
.getArch() == llvm::Triple::x86
)
3502 CmdArgs
.push_back("elf_i386");
3503 else if (ToolChain
.getArch() == llvm::Triple::arm
)
3504 CmdArgs
.push_back("armelf_linux_eabi");
3506 CmdArgs
.push_back("elf_x86_64");
3508 if (Args
.hasArg(options::OPT_static
)) {
3509 if (ToolChain
.getArch() == llvm::Triple::arm
)
3510 CmdArgs
.push_back("-Bstatic");
3512 CmdArgs
.push_back("-static");
3513 } else if (Args
.hasArg(options::OPT_shared
)) {
3514 CmdArgs
.push_back("-shared");
3517 if (ToolChain
.getArch() == llvm::Triple::arm
||
3518 (!Args
.hasArg(options::OPT_static
) &&
3519 !Args
.hasArg(options::OPT_shared
))) {
3520 CmdArgs
.push_back("-dynamic-linker");
3521 if (ToolChain
.getArch() == llvm::Triple::x86
)
3522 CmdArgs
.push_back("/lib/ld-linux.so.2");
3523 else if (ToolChain
.getArch() == llvm::Triple::arm
)
3524 CmdArgs
.push_back("/lib/ld-linux.so.3");
3526 CmdArgs
.push_back("/lib64/ld-linux-x86-64.so.2");
3529 CmdArgs
.push_back("-o");
3530 CmdArgs
.push_back(Output
.getFilename());
3532 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3533 !Args
.hasArg(options::OPT_nostartfiles
)) {
3534 const char *crt1
= NULL
;
3535 if (!Args
.hasArg(options::OPT_shared
)){
3536 if (Args
.hasArg(options::OPT_pie
))
3542 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath(crt1
)));
3544 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath("crti.o")));
3546 const char *crtbegin
;
3547 if (Args
.hasArg(options::OPT_static
))
3548 crtbegin
= "crtbeginT.o";
3549 else if (Args
.hasArg(options::OPT_shared
) || Args
.hasArg(options::OPT_pie
))
3550 crtbegin
= "crtbeginS.o";
3552 crtbegin
= "crtbegin.o";
3553 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath(crtbegin
)));
3556 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3558 const ToolChain::path_list Paths
= ToolChain
.getFilePaths();
3560 for (ToolChain::path_list::const_iterator i
= Paths
.begin(),
3563 const std::string
&s
= *i
;
3564 CmdArgs
.push_back(Args
.MakeArgString(std::string("-L") + s
));
3567 AddLinkerInputs(ToolChain
, Inputs
, Args
, CmdArgs
);
3569 if (D
.CCCIsCXX
&& !Args
.hasArg(options::OPT_nostdlib
)) {
3570 ToolChain
.AddCXXStdlibLibArgs(Args
, CmdArgs
);
3571 CmdArgs
.push_back("-lm");
3574 if (Args
.hasArg(options::OPT_static
))
3575 CmdArgs
.push_back("--start-group");
3577 if (!Args
.hasArg(options::OPT_nostdlib
)) {
3579 CmdArgs
.push_back("-lgcc");
3581 if (Args
.hasArg(options::OPT_static
)) {
3583 CmdArgs
.push_back("-lgcc");
3586 CmdArgs
.push_back("--as-needed");
3587 CmdArgs
.push_back("-lgcc_s");
3589 CmdArgs
.push_back("--no-as-needed");
3592 if (Args
.hasArg(options::OPT_static
))
3593 CmdArgs
.push_back("-lgcc_eh");
3594 else if (!Args
.hasArg(options::OPT_shared
) && D
.CCCIsCXX
)
3595 CmdArgs
.push_back("-lgcc");
3597 if (Args
.hasArg(options::OPT_pthread
) ||
3598 Args
.hasArg(options::OPT_pthreads
))
3599 CmdArgs
.push_back("-lpthread");
3601 CmdArgs
.push_back("-lc");
3603 if (Args
.hasArg(options::OPT_static
))
3604 CmdArgs
.push_back("--end-group");
3607 CmdArgs
.push_back("-lgcc");
3610 CmdArgs
.push_back("--as-needed");
3611 CmdArgs
.push_back("-lgcc_s");
3613 CmdArgs
.push_back("--no-as-needed");
3615 if (!Args
.hasArg(options::OPT_shared
) && D
.CCCIsCXX
)
3616 CmdArgs
.push_back("-lgcc");
3620 if (!Args
.hasArg(options::OPT_nostartfiles
)) {
3622 if (Args
.hasArg(options::OPT_shared
) || Args
.hasArg(options::OPT_pie
))
3623 crtend
= "crtendS.o";
3625 crtend
= "crtend.o";
3627 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath(crtend
)));
3628 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath("crtn.o")));
3632 if (Args
.hasArg(options::OPT_use_gold_plugin
)) {
3633 CmdArgs
.push_back("-plugin");
3634 std::string Plugin
= ToolChain
.getDriver().Dir
+ "/../lib/LLVMgold.so";
3635 CmdArgs
.push_back(Args
.MakeArgString(Plugin
));
3638 C
.addCommand(new Command(JA
, *this, ToolChain
.Linker
.c_str(), CmdArgs
));
3641 void minix::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3642 const InputInfo
&Output
,
3643 const InputInfoList
&Inputs
,
3644 const ArgList
&Args
,
3645 const char *LinkingOutput
) const {
3646 ArgStringList CmdArgs
;
3648 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3649 options::OPT_Xassembler
);
3651 CmdArgs
.push_back("-o");
3652 CmdArgs
.push_back(Output
.getFilename());
3654 for (InputInfoList::const_iterator
3655 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3656 const InputInfo
&II
= *it
;
3657 CmdArgs
.push_back(II
.getFilename());
3661 Args
.MakeArgString(getToolChain().GetProgramPath("gas"));
3662 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3665 void minix::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3666 const InputInfo
&Output
,
3667 const InputInfoList
&Inputs
,
3668 const ArgList
&Args
,
3669 const char *LinkingOutput
) const {
3670 const Driver
&D
= getToolChain().getDriver();
3671 ArgStringList CmdArgs
;
3673 if (Output
.isFilename()) {
3674 CmdArgs
.push_back("-o");
3675 CmdArgs
.push_back(Output
.getFilename());
3677 assert(Output
.isNothing() && "Invalid output.");
3680 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3681 !Args
.hasArg(options::OPT_nostartfiles
))
3682 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3683 "/usr/gnu/lib/crtso.o")));
3685 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3686 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3687 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3689 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3691 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3692 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3694 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3695 CmdArgs
.push_back("-lm");
3698 if (Args
.hasArg(options::OPT_pthread
))
3699 CmdArgs
.push_back("-lpthread");
3700 CmdArgs
.push_back("-lc");
3701 CmdArgs
.push_back("-lgcc");
3702 CmdArgs
.push_back("-L/usr/gnu/lib");
3703 // FIXME: fill in the correct search path for the final
3704 // support libraries.
3705 CmdArgs
.push_back("-L/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
3708 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3709 !Args
.hasArg(options::OPT_nostartfiles
)) {
3710 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3711 "/usr/gnu/lib/libend.a")));
3715 Args
.MakeArgString(getToolChain().GetProgramPath("/usr/gnu/bin/gld"));
3716 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3721 // For now, DragonFly Assemble does just about the same as for
3722 // FreeBSD, but this may change soon.
3723 void dragonfly::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3724 const InputInfo
&Output
,
3725 const InputInfoList
&Inputs
,
3726 const ArgList
&Args
,
3727 const char *LinkingOutput
) const {
3728 ArgStringList CmdArgs
;
3730 // When building 32-bit code on DragonFly/pc64, we have to explicitly
3731 // instruct as in the base system to assemble 32-bit code.
3732 if (getToolChain().getArchName() == "i386")
3733 CmdArgs
.push_back("--32");
3735 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3736 options::OPT_Xassembler
);
3738 CmdArgs
.push_back("-o");
3739 CmdArgs
.push_back(Output
.getFilename());
3741 for (InputInfoList::const_iterator
3742 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3743 const InputInfo
&II
= *it
;
3744 CmdArgs
.push_back(II
.getFilename());
3748 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3749 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3752 void dragonfly::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3753 const InputInfo
&Output
,
3754 const InputInfoList
&Inputs
,
3755 const ArgList
&Args
,
3756 const char *LinkingOutput
) const {
3757 const Driver
&D
= getToolChain().getDriver();
3758 ArgStringList CmdArgs
;
3760 if (Args
.hasArg(options::OPT_static
)) {
3761 CmdArgs
.push_back("-Bstatic");
3763 if (Args
.hasArg(options::OPT_shared
))
3764 CmdArgs
.push_back("-Bshareable");
3766 CmdArgs
.push_back("-dynamic-linker");
3767 CmdArgs
.push_back("/usr/libexec/ld-elf.so.2");
3771 // When building 32-bit code on DragonFly/pc64, we have to explicitly
3772 // instruct ld in the base system to link 32-bit code.
3773 if (getToolChain().getArchName() == "i386") {
3774 CmdArgs
.push_back("-m");
3775 CmdArgs
.push_back("elf_i386");
3778 if (Output
.isFilename()) {
3779 CmdArgs
.push_back("-o");
3780 CmdArgs
.push_back(Output
.getFilename());
3782 assert(Output
.isNothing() && "Invalid output.");
3785 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3786 !Args
.hasArg(options::OPT_nostartfiles
)) {
3787 if (!Args
.hasArg(options::OPT_shared
)) {
3789 Args
.MakeArgString(getToolChain().GetFilePath("crt1.o")));
3791 Args
.MakeArgString(getToolChain().GetFilePath("crti.o")));
3793 Args
.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
3796 Args
.MakeArgString(getToolChain().GetFilePath("crti.o")));
3798 Args
.MakeArgString(getToolChain().GetFilePath("crtbeginS.o")));
3802 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3803 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3804 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3806 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3808 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3809 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3810 // FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of
3812 CmdArgs
.push_back("-L/usr/lib/gcc41");
3814 if (!Args
.hasArg(options::OPT_static
)) {
3815 CmdArgs
.push_back("-rpath");
3816 CmdArgs
.push_back("/usr/lib/gcc41");
3818 CmdArgs
.push_back("-rpath-link");
3819 CmdArgs
.push_back("/usr/lib/gcc41");
3821 CmdArgs
.push_back("-rpath");
3822 CmdArgs
.push_back("/usr/lib");
3824 CmdArgs
.push_back("-rpath-link");
3825 CmdArgs
.push_back("/usr/lib");
3829 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3830 CmdArgs
.push_back("-lm");
3833 if (Args
.hasArg(options::OPT_shared
)) {
3834 CmdArgs
.push_back("-lgcc_pic");
3836 CmdArgs
.push_back("-lgcc");
3840 if (Args
.hasArg(options::OPT_pthread
))
3841 CmdArgs
.push_back("-lpthread");
3843 if (!Args
.hasArg(options::OPT_nolibc
)) {
3844 CmdArgs
.push_back("-lc");
3847 if (Args
.hasArg(options::OPT_shared
)) {
3848 CmdArgs
.push_back("-lgcc_pic");
3850 CmdArgs
.push_back("-lgcc");
3854 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3855 !Args
.hasArg(options::OPT_nostartfiles
)) {
3856 if (!Args
.hasArg(options::OPT_shared
))
3857 CmdArgs
.push_back(Args
.MakeArgString(
3858 getToolChain().GetFilePath("crtend.o")));
3860 CmdArgs
.push_back(Args
.MakeArgString(
3861 getToolChain().GetFilePath("crtendS.o")));
3862 CmdArgs
.push_back(Args
.MakeArgString(
3863 getToolChain().GetFilePath("crtn.o")));
3867 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3868 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3871 void visualstudio::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3872 const InputInfo
&Output
,
3873 const InputInfoList
&Inputs
,
3874 const ArgList
&Args
,
3875 const char *LinkingOutput
) const {
3876 ArgStringList CmdArgs
;
3878 if (Output
.isFilename()) {
3879 CmdArgs
.push_back(Args
.MakeArgString(std::string("-out:") +
3880 Output
.getFilename()));
3882 assert(Output
.isNothing() && "Invalid output.");
3885 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3886 !Args
.hasArg(options::OPT_nostartfiles
)) {
3887 CmdArgs
.push_back("-defaultlib:libcmt");
3890 CmdArgs
.push_back("-nologo");
3892 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3895 Args
.MakeArgString(getToolChain().GetProgramPath("link.exe"));
3896 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));