1 //===--- Tools.cpp - Tools Implementations --------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 #include "clang/Driver/Action.h"
13 #include "clang/Driver/Arg.h"
14 #include "clang/Driver/ArgList.h"
15 #include "clang/Driver/Driver.h"
16 #include "clang/Driver/DriverDiagnostic.h"
17 #include "clang/Driver/Compilation.h"
18 #include "clang/Driver/Job.h"
19 #include "clang/Driver/HostInfo.h"
20 #include "clang/Driver/Option.h"
21 #include "clang/Driver/Options.h"
22 #include "clang/Driver/ToolChain.h"
23 #include "clang/Driver/Util.h"
25 #include "llvm/ADT/SmallString.h"
26 #include "llvm/ADT/StringSwitch.h"
27 #include "llvm/ADT/Twine.h"
28 #include "llvm/Support/Format.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include "llvm/Support/Host.h"
31 #include "llvm/Support/Process.h"
33 #include "InputInfo.h"
34 #include "ToolChains.h"
36 using namespace clang::driver
;
37 using namespace clang::driver::tools
;
39 /// CheckPreprocessingOptions - Perform some validation of preprocessing
40 /// arguments that is shared with gcc.
41 static void CheckPreprocessingOptions(const Driver
&D
, const ArgList
&Args
) {
42 if (Arg
*A
= Args
.getLastArg(options::OPT_C
, options::OPT_CC
))
43 if (!Args
.hasArg(options::OPT_E
))
44 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
45 << A
->getAsString(Args
) << "-E";
48 /// CheckCodeGenerationOptions - Perform some validation of code generation
49 /// arguments that is shared with gcc.
50 static void CheckCodeGenerationOptions(const Driver
&D
, const ArgList
&Args
) {
51 // In gcc, only ARM checks this, but it seems reasonable to check universally.
52 if (Args
.hasArg(options::OPT_static
))
53 if (const Arg
*A
= Args
.getLastArg(options::OPT_dynamic
,
54 options::OPT_mdynamic_no_pic
))
55 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
56 << A
->getAsString(Args
) << "-static";
59 // Quote target names for inclusion in GNU Make dependency files.
60 // Only the characters '$', '#', ' ', '\t' are quoted.
61 static void QuoteTarget(llvm::StringRef Target
,
62 llvm::SmallVectorImpl
<char> &Res
) {
63 for (unsigned i
= 0, e
= Target
.size(); i
!= e
; ++i
) {
67 // Escape the preceding backslashes
68 for (int j
= i
- 1; j
>= 0 && Target
[j
] == '\\'; --j
)
71 // Escape the space/tab
84 Res
.push_back(Target
[i
]);
88 static void AddLinkerInputs(const ToolChain
&TC
,
89 const InputInfoList
&Inputs
, const ArgList
&Args
,
90 ArgStringList
&CmdArgs
) {
91 const Driver
&D
= TC
.getDriver();
93 for (InputInfoList::const_iterator
94 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
95 const InputInfo
&II
= *it
;
97 if (!TC
.HasNativeLLVMSupport()) {
98 // Don't try to pass LLVM inputs unless we have native support.
99 if (II
.getType() == types::TY_LLVM_IR
||
100 II
.getType() == types::TY_LTO_IR
||
101 II
.getType() == types::TY_LLVM_BC
||
102 II
.getType() == types::TY_LTO_BC
)
103 D
.Diag(clang::diag::err_drv_no_linker_llvm_support
)
104 << TC
.getTripleString();
107 // Add filenames immediately.
108 if (II
.isFilename()) {
109 CmdArgs
.push_back(II
.getFilename());
113 // Otherwise, this is a linker input argument.
114 const Arg
&A
= II
.getInputArg();
116 // Handle reserved library options.
117 if (A
.getOption().matches(options::OPT_Z_reserved_lib_stdcxx
)) {
118 TC
.AddCXXStdlibLibArgs(Args
, CmdArgs
);
119 } else if (A
.getOption().matches(options::OPT_Z_reserved_lib_cckext
)) {
120 TC
.AddCCKextLibArgs(Args
, CmdArgs
);
122 A
.renderAsInput(Args
, CmdArgs
);
126 void Clang::AddPreprocessingOptions(const Driver
&D
,
128 ArgStringList
&CmdArgs
,
129 const InputInfo
&Output
,
130 const InputInfoList
&Inputs
) const {
133 CheckPreprocessingOptions(D
, Args
);
135 Args
.AddLastArg(CmdArgs
, options::OPT_C
);
136 Args
.AddLastArg(CmdArgs
, options::OPT_CC
);
138 // Handle dependency file generation.
139 if ((A
= Args
.getLastArg(options::OPT_M
)) ||
140 (A
= Args
.getLastArg(options::OPT_MM
)) ||
141 (A
= Args
.getLastArg(options::OPT_MD
)) ||
142 (A
= Args
.getLastArg(options::OPT_MMD
))) {
143 // Determine the output location.
145 if (Output
.getType() == types::TY_Dependencies
) {
146 DepFile
= Output
.getFilename();
147 } else if (Arg
*MF
= Args
.getLastArg(options::OPT_MF
)) {
148 DepFile
= MF
->getValue(Args
);
149 } else if (A
->getOption().matches(options::OPT_M
) ||
150 A
->getOption().matches(options::OPT_MM
)) {
153 DepFile
= darwin::CC1::getDependencyFileName(Args
, Inputs
);
155 CmdArgs
.push_back("-dependency-file");
156 CmdArgs
.push_back(DepFile
);
158 // Add a default target if one wasn't specified.
159 if (!Args
.hasArg(options::OPT_MT
) && !Args
.hasArg(options::OPT_MQ
)) {
160 const char *DepTarget
;
162 // If user provided -o, that is the dependency target, except
163 // when we are only generating a dependency file.
164 Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
);
165 if (OutputOpt
&& Output
.getType() != types::TY_Dependencies
) {
166 DepTarget
= OutputOpt
->getValue(Args
);
168 // Otherwise derive from the base input.
170 // FIXME: This should use the computed output file location.
171 llvm::sys::Path
P(Inputs
[0].getBaseInput());
175 DepTarget
= Args
.MakeArgString(P
.getLast());
178 CmdArgs
.push_back("-MT");
179 llvm::SmallString
<128> Quoted
;
180 QuoteTarget(DepTarget
, Quoted
);
181 CmdArgs
.push_back(Args
.MakeArgString(Quoted
));
184 if (A
->getOption().matches(options::OPT_M
) ||
185 A
->getOption().matches(options::OPT_MD
))
186 CmdArgs
.push_back("-sys-header-deps");
189 Args
.AddLastArg(CmdArgs
, options::OPT_MP
);
191 // Convert all -MQ <target> args to -MT <quoted target>
192 for (arg_iterator it
= Args
.filtered_begin(options::OPT_MT
,
194 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
198 if (A
->getOption().matches(options::OPT_MQ
)) {
199 CmdArgs
.push_back("-MT");
200 llvm::SmallString
<128> Quoted
;
201 QuoteTarget(A
->getValue(Args
), Quoted
);
202 CmdArgs
.push_back(Args
.MakeArgString(Quoted
));
204 // -MT flag - no change
206 A
->render(Args
, CmdArgs
);
210 // Add -i* options, and automatically translate to
211 // -include-pch/-include-pth for transparent PCH support. It's
212 // wonky, but we include looking for .gch so we can support seamless
213 // replacement into a build system already set up to be generating
215 bool RenderedImplicitInclude
= false;
216 for (arg_iterator it
= Args
.filtered_begin(options::OPT_clang_i_Group
),
217 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
220 if (A
->getOption().matches(options::OPT_include
)) {
221 bool IsFirstImplicitInclude
= !RenderedImplicitInclude
;
222 RenderedImplicitInclude
= true;
224 // Use PCH if the user requested it.
225 bool UsePCH
= D
.CCCUsePCH
;
227 bool FoundPTH
= false;
228 bool FoundPCH
= false;
229 llvm::sys::Path
P(A
->getValue(Args
));
231 P
.appendSuffix("pch");
239 P
.appendSuffix("pth");
246 if (!FoundPCH
&& !FoundPTH
) {
247 P
.appendSuffix("gch");
256 if (FoundPCH
|| FoundPTH
) {
257 if (IsFirstImplicitInclude
) {
260 CmdArgs
.push_back("-include-pch");
262 CmdArgs
.push_back("-include-pth");
263 CmdArgs
.push_back(Args
.MakeArgString(P
.str()));
266 // Ignore the PCH if not first on command line and emit warning.
267 D
.Diag(clang::diag::warn_drv_pch_not_first_include
)
268 << P
.str() << A
->getAsString(Args
);
273 // Not translated, render as usual.
275 A
->render(Args
, CmdArgs
);
278 Args
.AddAllArgs(CmdArgs
, options::OPT_D
, options::OPT_U
);
279 Args
.AddAllArgs(CmdArgs
, options::OPT_I_Group
, options::OPT_F
);
281 // Add C++ include arguments, if needed.
282 types::ID InputType
= Inputs
[0].getType();
283 if (types::isCXX(InputType
))
284 getToolChain().AddClangCXXStdlibIncludeArgs(Args
, CmdArgs
);
286 // Add -Wp, and -Xassembler if using the preprocessor.
288 // FIXME: There is a very unfortunate problem here, some troubled
289 // souls abuse -Wp, to pass preprocessor options in gcc syntax. To
290 // really support that we would have to parse and then translate
292 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wp_COMMA
,
293 options::OPT_Xpreprocessor
);
295 // -I- is a deprecated GCC feature, reject it.
296 if (Arg
*A
= Args
.getLastArg(options::OPT_I_
))
297 D
.Diag(clang::diag::err_drv_I_dash_not_supported
) << A
->getAsString(Args
);
299 // If we have a --sysroot, and don't have an explicit -isysroot flag, add an
300 // -isysroot to the CC1 invocation.
301 if (Arg
*A
= Args
.getLastArg(options::OPT__sysroot_EQ
)) {
302 if (!Args
.hasArg(options::OPT_isysroot
)) {
303 CmdArgs
.push_back("-isysroot");
304 CmdArgs
.push_back(A
->getValue(Args
));
309 /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targetting.
311 // FIXME: tblgen this.
312 static const char *getARMTargetCPU(const ArgList
&Args
,
313 const llvm::Triple
&Triple
) {
314 // FIXME: Warn on inconsistent use of -mcpu and -march.
316 // If we have -mcpu=, use that.
317 if (Arg
*A
= Args
.getLastArg(options::OPT_mcpu_EQ
))
318 return A
->getValue(Args
);
320 llvm::StringRef MArch
;
321 if (Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
322 // Otherwise, if we have -march= choose the base CPU for that arch.
323 MArch
= A
->getValue(Args
);
325 // Otherwise, use the Arch from the triple.
326 MArch
= Triple
.getArchName();
329 if (MArch
== "armv2" || MArch
== "armv2a")
331 if (MArch
== "armv3")
333 if (MArch
== "armv3m")
335 if (MArch
== "armv4" || MArch
== "armv4t")
337 if (MArch
== "armv5" || MArch
== "armv5t")
339 if (MArch
== "armv5e" || MArch
== "armv5te")
341 if (MArch
== "armv5tej")
343 if (MArch
== "armv6" || MArch
== "armv6k")
344 return "arm1136jf-s";
345 if (MArch
== "armv6j")
347 if (MArch
== "armv6z" || MArch
== "armv6zk")
348 return "arm1176jzf-s";
349 if (MArch
== "armv6t2")
350 return "arm1156t2-s";
351 if (MArch
== "armv7" || MArch
== "armv7a" || MArch
== "armv7-a")
353 if (MArch
== "armv7r" || MArch
== "armv7-r")
355 if (MArch
== "armv7m" || MArch
== "armv7-m")
357 if (MArch
== "ep9312")
359 if (MArch
== "iwmmxt")
361 if (MArch
== "xscale")
364 // If all else failed, return the most base CPU LLVM supports.
368 /// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular
371 // FIXME: This is redundant with -mcpu, why does LLVM use this.
372 // FIXME: tblgen this, or kill it!
373 static const char *getLLVMArchSuffixForARM(llvm::StringRef CPU
) {
374 if (CPU
== "arm7tdmi" || CPU
== "arm7tdmi-s" || CPU
== "arm710t" ||
375 CPU
== "arm720t" || CPU
== "arm9" || CPU
== "arm9tdmi" ||
376 CPU
== "arm920" || CPU
== "arm920t" || CPU
== "arm922t" ||
377 CPU
== "arm940t" || CPU
== "ep9312")
380 if (CPU
== "arm10tdmi" || CPU
== "arm1020t")
383 if (CPU
== "arm9e" || CPU
== "arm926ej-s" || CPU
== "arm946e-s" ||
384 CPU
== "arm966e-s" || CPU
== "arm968e-s" || CPU
== "arm10e" ||
385 CPU
== "arm1020e" || CPU
== "arm1022e" || CPU
== "xscale" ||
389 if (CPU
== "arm1136j-s" || CPU
== "arm1136jf-s" || CPU
== "arm1176jz-s" ||
390 CPU
== "arm1176jzf-s" || CPU
== "mpcorenovfp" || CPU
== "mpcore")
393 if (CPU
== "arm1156t2-s" || CPU
== "arm1156t2f-s")
396 if (CPU
== "cortex-a8" || CPU
== "cortex-a9")
402 // FIXME: Move to target hook.
403 static bool isSignedCharDefault(const llvm::Triple
&Triple
) {
404 switch (Triple
.getArch()) {
408 case llvm::Triple::ppc
:
409 case llvm::Triple::ppc64
:
410 if (Triple
.getOS() == llvm::Triple::Darwin
)
414 case llvm::Triple::systemz
:
419 void Clang::AddARMTargetArgs(const ArgList
&Args
,
420 ArgStringList
&CmdArgs
) const {
421 const Driver
&D
= getToolChain().getDriver();
422 llvm::Triple Triple
= getToolChain().getTriple();
424 // Select the ABI to use.
426 // FIXME: Support -meabi.
427 const char *ABIName
= 0;
428 if (Arg
*A
= Args
.getLastArg(options::OPT_mabi_EQ
)) {
429 ABIName
= A
->getValue(Args
);
431 // Select the default based on the platform.
432 llvm::StringRef env
= Triple
.getEnvironmentName();
433 if (env
== "gnueabi")
434 ABIName
= "aapcs-linux";
435 else if (env
== "eabi")
438 ABIName
= "apcs-gnu";
440 CmdArgs
.push_back("-target-abi");
441 CmdArgs
.push_back(ABIName
);
443 // Set the CPU based on -march= and -mcpu=.
444 CmdArgs
.push_back("-target-cpu");
445 CmdArgs
.push_back(getARMTargetCPU(Args
, Triple
));
447 // Select the float ABI as determined by -msoft-float, -mhard-float, and
449 llvm::StringRef FloatABI
;
450 if (Arg
*A
= Args
.getLastArg(options::OPT_msoft_float
,
451 options::OPT_mhard_float
,
452 options::OPT_mfloat_abi_EQ
)) {
453 if (A
->getOption().matches(options::OPT_msoft_float
))
455 else if (A
->getOption().matches(options::OPT_mhard_float
))
458 FloatABI
= A
->getValue(Args
);
459 if (FloatABI
!= "soft" && FloatABI
!= "softfp" && FloatABI
!= "hard") {
460 D
.Diag(clang::diag::err_drv_invalid_mfloat_abi
)
461 << A
->getAsString(Args
);
467 // If unspecified, choose the default based on the platform.
468 if (FloatABI
.empty()) {
469 const llvm::Triple
&Triple
= getToolChain().getTriple();
470 switch (Triple
.getOS()) {
471 case llvm::Triple::Darwin
: {
472 // Darwin defaults to "softfp" for v6 and v7.
474 // FIXME: Factor out an ARM class so we can cache the arch somewhere.
475 llvm::StringRef ArchName
=
476 getLLVMArchSuffixForARM(getARMTargetCPU(Args
, Triple
));
477 if (ArchName
.startswith("v6") || ArchName
.startswith("v7"))
484 case llvm::Triple::Linux
: {
485 llvm::StringRef Env
= getToolChain().getTriple().getEnvironmentName();
486 if (Env
== "gnueabi") {
494 // Assume "soft", but warn the user we are guessing.
496 D
.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is
) << "soft";
501 if (FloatABI
== "soft") {
502 // Floating point operations and argument passing are soft.
504 // FIXME: This changes CPP defines, we need -target-soft-float.
505 CmdArgs
.push_back("-msoft-float");
506 CmdArgs
.push_back("-mfloat-abi");
507 CmdArgs
.push_back("soft");
508 } else if (FloatABI
== "softfp") {
509 // Floating point operations are hard, but argument passing is soft.
510 CmdArgs
.push_back("-mfloat-abi");
511 CmdArgs
.push_back("soft");
513 // Floating point operations and argument passing are hard.
514 assert(FloatABI
== "hard" && "Invalid float abi!");
515 CmdArgs
.push_back("-mfloat-abi");
516 CmdArgs
.push_back("hard");
519 // Set appropriate target features for floating point mode.
521 // FIXME: Note, this is a hack, the LLVM backend doesn't actually use these
522 // yet (it uses the -mfloat-abi and -msoft-float options above), and it is
523 // stripped out by the ARM target.
525 // Use software floating point operations?
526 if (FloatABI
== "soft") {
527 CmdArgs
.push_back("-target-feature");
528 CmdArgs
.push_back("+soft-float");
531 // Use software floating point argument passing?
532 if (FloatABI
!= "hard") {
533 CmdArgs
.push_back("-target-feature");
534 CmdArgs
.push_back("+soft-float-abi");
539 // FIXME: Centralize feature selection, defaulting shouldn't be also in the
541 if (const Arg
*A
= Args
.getLastArg(options::OPT_mfpu_EQ
)) {
542 llvm::StringRef FPU
= A
->getValue(Args
);
544 // Set the target features based on the FPU.
545 if (FPU
== "fpa" || FPU
== "fpe2" || FPU
== "fpe3" || FPU
== "maverick") {
546 // Disable any default FPU support.
547 CmdArgs
.push_back("-target-feature");
548 CmdArgs
.push_back("-vfp2");
549 CmdArgs
.push_back("-target-feature");
550 CmdArgs
.push_back("-vfp3");
551 CmdArgs
.push_back("-target-feature");
552 CmdArgs
.push_back("-neon");
553 } else if (FPU
== "vfp") {
554 CmdArgs
.push_back("-target-feature");
555 CmdArgs
.push_back("+vfp2");
556 } else if (FPU
== "vfp3") {
557 CmdArgs
.push_back("-target-feature");
558 CmdArgs
.push_back("+vfp3");
559 } else if (FPU
== "neon") {
560 CmdArgs
.push_back("-target-feature");
561 CmdArgs
.push_back("+neon");
563 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
567 void Clang::AddMIPSTargetArgs(const ArgList
&Args
,
568 ArgStringList
&CmdArgs
) const {
569 const Driver
&D
= getToolChain().getDriver();
571 // Select the ABI to use.
572 const char *ABIName
= 0;
573 if (Arg
*A
= Args
.getLastArg(options::OPT_mabi_EQ
)) {
574 ABIName
= A
->getValue(Args
);
579 CmdArgs
.push_back("-target-abi");
580 CmdArgs
.push_back(ABIName
);
582 if (const Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
583 llvm::StringRef MArch
= A
->getValue(Args
);
584 CmdArgs
.push_back("-target-cpu");
586 if ((MArch
== "r2000") || (MArch
== "r3000"))
587 CmdArgs
.push_back("mips1");
588 else if (MArch
== "r6000")
589 CmdArgs
.push_back("mips2");
591 CmdArgs
.push_back(MArch
.str().c_str());
594 // Select the float ABI as determined by -msoft-float, -mhard-float, and
595 llvm::StringRef FloatABI
;
596 if (Arg
*A
= Args
.getLastArg(options::OPT_msoft_float
,
597 options::OPT_mhard_float
)) {
598 if (A
->getOption().matches(options::OPT_msoft_float
))
600 else if (A
->getOption().matches(options::OPT_mhard_float
))
604 // If unspecified, choose the default based on the platform.
605 if (FloatABI
.empty()) {
606 // Assume "soft", but warn the user we are guessing.
608 D
.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is
) << "soft";
611 if (FloatABI
== "soft") {
612 // Floating point operations and argument passing are soft.
614 // FIXME: This changes CPP defines, we need -target-soft-float.
615 CmdArgs
.push_back("-msoft-float");
617 assert(FloatABI
== "hard" && "Invalid float abi!");
618 CmdArgs
.push_back("-mhard-float");
622 void Clang::AddSparcTargetArgs(const ArgList
&Args
,
623 ArgStringList
&CmdArgs
) const {
624 const Driver
&D
= getToolChain().getDriver();
626 if (const Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
627 llvm::StringRef MArch
= A
->getValue(Args
);
628 CmdArgs
.push_back("-target-cpu");
629 CmdArgs
.push_back(MArch
.str().c_str());
632 // Select the float ABI as determined by -msoft-float, -mhard-float, and
633 llvm::StringRef FloatABI
;
634 if (Arg
*A
= Args
.getLastArg(options::OPT_msoft_float
,
635 options::OPT_mhard_float
)) {
636 if (A
->getOption().matches(options::OPT_msoft_float
))
638 else if (A
->getOption().matches(options::OPT_mhard_float
))
642 // If unspecified, choose the default based on the platform.
643 if (FloatABI
.empty()) {
644 switch (getToolChain().getTriple().getOS()) {
646 // Assume "soft", but warn the user we are guessing.
648 D
.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is
) << "soft";
653 if (FloatABI
== "soft") {
654 // Floating point operations and argument passing are soft.
656 // FIXME: This changes CPP defines, we need -target-soft-float.
657 CmdArgs
.push_back("-msoft-float");
658 CmdArgs
.push_back("soft");
659 CmdArgs
.push_back("-target-feature");
660 CmdArgs
.push_back("+soft-float");
662 assert(FloatABI
== "hard" && "Invalid float abi!");
663 CmdArgs
.push_back("-mhard-float");
667 void Clang::AddX86TargetArgs(const ArgList
&Args
,
668 ArgStringList
&CmdArgs
) const {
669 if (!Args
.hasFlag(options::OPT_mred_zone
,
670 options::OPT_mno_red_zone
,
672 Args
.hasArg(options::OPT_mkernel
) ||
673 Args
.hasArg(options::OPT_fapple_kext
))
674 CmdArgs
.push_back("-disable-red-zone");
676 if (Args
.hasFlag(options::OPT_msoft_float
,
677 options::OPT_mno_soft_float
,
679 CmdArgs
.push_back("-no-implicit-float");
681 const char *CPUName
= 0;
682 if (const Arg
*A
= Args
.getLastArg(options::OPT_march_EQ
)) {
683 if (llvm::StringRef(A
->getValue(Args
)) == "native") {
684 // FIXME: Reject attempts to use -march=native unless the target matches
687 // FIXME: We should also incorporate the detected target features for use
689 std::string CPU
= llvm::sys::getHostCPUName();
691 CPUName
= Args
.MakeArgString(CPU
);
693 CPUName
= A
->getValue(Args
);
696 // Select the default CPU if none was given (or detection failed).
698 // FIXME: Need target hooks.
699 if (getToolChain().getOS().startswith("darwin")) {
700 if (getToolChain().getArchName() == "x86_64")
702 else if (getToolChain().getArchName() == "i386")
704 } else if (getToolChain().getOS().startswith("haiku")) {
705 if (getToolChain().getArchName() == "x86_64")
707 else if (getToolChain().getArchName() == "i386")
709 } else if (getToolChain().getOS().startswith("openbsd")) {
710 if (getToolChain().getArchName() == "x86_64")
712 else if (getToolChain().getArchName() == "i386")
715 if (getToolChain().getArchName() == "x86_64")
717 else if (getToolChain().getArchName() == "i386")
718 CPUName
= "pentium4";
723 CmdArgs
.push_back("-target-cpu");
724 CmdArgs
.push_back(CPUName
);
727 for (arg_iterator it
= Args
.filtered_begin(options::OPT_m_x86_Features_Group
),
728 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
729 llvm::StringRef Name
= (*it
)->getOption().getName();
733 assert(Name
.startswith("-m") && "Invalid feature name.");
734 Name
= Name
.substr(2);
736 bool IsNegative
= Name
.startswith("no-");
738 Name
= Name
.substr(3);
740 CmdArgs
.push_back("-target-feature");
741 CmdArgs
.push_back(Args
.MakeArgString((IsNegative
? "-" : "+") + Name
));
745 static bool needsExceptions(const ArgList
&Args
, types::ID InputType
,
746 const llvm::Triple
&Triple
) {
747 // Handle -fno-exceptions.
748 if (Arg
*A
= Args
.getLastArg(options::OPT_fexceptions
,
749 options::OPT_fno_exceptions
)) {
750 if (A
->getOption().matches(options::OPT_fexceptions
))
756 // Otherwise, C++ inputs use exceptions.
757 if (types::isCXX(InputType
))
760 // As do Objective-C non-fragile ABI inputs and all Objective-C inputs on
761 // x86_64 and ARM after SnowLeopard.
762 if (types::isObjC(InputType
)) {
763 if (Args
.hasArg(options::OPT_fobjc_nonfragile_abi
))
765 if (Triple
.getOS() != llvm::Triple::Darwin
)
767 return (Triple
.getDarwinMajorNumber() >= 9 &&
768 (Triple
.getArch() == llvm::Triple::x86_64
||
769 Triple
.getArch() == llvm::Triple::arm
));
775 void Clang::ConstructJob(Compilation
&C
, const JobAction
&JA
,
776 const InputInfo
&Output
,
777 const InputInfoList
&Inputs
,
779 const char *LinkingOutput
) const {
780 bool KernelOrKext
= Args
.hasArg(options::OPT_mkernel
,
781 options::OPT_fapple_kext
);
782 const Driver
&D
= getToolChain().getDriver();
783 ArgStringList CmdArgs
;
785 assert(Inputs
.size() == 1 && "Unable to handle multiple inputs.");
787 // Invoke ourselves in -cc1 mode.
789 // FIXME: Implement custom jobs for internal actions.
790 CmdArgs
.push_back("-cc1");
792 // Add the "effective" target triple.
793 CmdArgs
.push_back("-triple");
794 std::string TripleStr
= getToolChain().ComputeEffectiveClangTriple(Args
);
795 CmdArgs
.push_back(Args
.MakeArgString(TripleStr
));
797 // Select the appropriate action.
798 bool IsRewriter
= false;
799 if (isa
<AnalyzeJobAction
>(JA
)) {
800 assert(JA
.getType() == types::TY_Plist
&& "Invalid output type.");
801 CmdArgs
.push_back("-analyze");
802 } else if (isa
<PreprocessJobAction
>(JA
)) {
803 if (Output
.getType() == types::TY_Dependencies
)
804 CmdArgs
.push_back("-Eonly");
806 CmdArgs
.push_back("-E");
807 } else if (isa
<AssembleJobAction
>(JA
)) {
808 CmdArgs
.push_back("-emit-obj");
810 // At -O0, we use -mrelax-all by default.
812 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
))
813 IsOpt
= !A
->getOption().matches(options::OPT_O0
);
814 if (Args
.hasFlag(options::OPT_mrelax_all
,
815 options::OPT_mno_relax_all
,
817 CmdArgs
.push_back("-mrelax-all");
819 // When using an integrated assembler, translate -Wa, and -Xassembler
821 for (arg_iterator it
= Args
.filtered_begin(options::OPT_Wa_COMMA
,
822 options::OPT_Xassembler
),
823 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
827 for (unsigned i
= 0, e
= A
->getNumValues(); i
!= e
; ++i
) {
828 llvm::StringRef Value
= A
->getValue(Args
, i
);
830 if (Value
== "-force_cpusubtype_ALL") {
831 // Do nothing, this is the default and we don't support anything else.
832 } else if (Value
== "-L") {
833 // We don't support -L yet, but it isn't important enough to error
834 // on. No one should really be using it for a semantic change.
835 D
.Diag(clang::diag::warn_drv_unsupported_option_argument
)
836 << A
->getOption().getName() << Value
;
838 D
.Diag(clang::diag::err_drv_unsupported_option_argument
)
839 << A
->getOption().getName() << Value
;
844 // Also ignore explicit -force_cpusubtype_ALL option.
845 (void) Args
.hasArg(options::OPT_force__cpusubtype__ALL
);
846 } else if (isa
<PrecompileJobAction
>(JA
)) {
847 // Use PCH if the user requested it.
848 bool UsePCH
= D
.CCCUsePCH
;
851 CmdArgs
.push_back("-emit-pch");
853 CmdArgs
.push_back("-emit-pth");
855 assert(isa
<CompileJobAction
>(JA
) && "Invalid action for clang tool.");
857 if (JA
.getType() == types::TY_Nothing
) {
858 CmdArgs
.push_back("-fsyntax-only");
859 } else if (JA
.getType() == types::TY_LLVM_IR
||
860 JA
.getType() == types::TY_LTO_IR
) {
861 CmdArgs
.push_back("-emit-llvm");
862 } else if (JA
.getType() == types::TY_LLVM_BC
||
863 JA
.getType() == types::TY_LTO_BC
) {
864 CmdArgs
.push_back("-emit-llvm-bc");
865 } else if (JA
.getType() == types::TY_PP_Asm
) {
866 CmdArgs
.push_back("-S");
867 } else if (JA
.getType() == types::TY_AST
) {
868 CmdArgs
.push_back("-emit-pch");
869 } else if (JA
.getType() == types::TY_RewrittenObjC
) {
870 CmdArgs
.push_back("-rewrite-objc");
873 assert(JA
.getType() == types::TY_PP_Asm
&&
874 "Unexpected output type!");
878 // The make clang go fast button.
879 CmdArgs
.push_back("-disable-free");
881 // Disable the verification pass in -asserts builds.
883 CmdArgs
.push_back("-disable-llvm-verifier");
886 // Set the main file name, so that debug info works even with
888 CmdArgs
.push_back("-main-file-name");
889 CmdArgs
.push_back(darwin::CC1::getBaseInputName(Args
, Inputs
));
891 // Some flags which affect the language (via preprocessor
892 // defines). See darwin::CC1::AddCPPArgs.
893 if (Args
.hasArg(options::OPT_static
))
894 CmdArgs
.push_back("-static-define");
896 if (isa
<AnalyzeJobAction
>(JA
)) {
897 // Enable region store model by default.
898 CmdArgs
.push_back("-analyzer-store=region");
900 // Treat blocks as analysis entry points.
901 CmdArgs
.push_back("-analyzer-opt-analyze-nested-blocks");
903 // Add default argument set.
904 if (!Args
.hasArg(options::OPT__analyzer_no_default_checks
)) {
905 CmdArgs
.push_back("-analyzer-check-dead-stores");
906 // Do not enable the security-syntatic check since it
907 // it needs to be refined (known issues).
908 // CmdArgs.push_back("-analyzer-check-security-syntactic");
909 CmdArgs
.push_back("-analyzer-check-objc-mem");
910 CmdArgs
.push_back("-analyzer-eagerly-assume");
911 CmdArgs
.push_back("-analyzer-check-objc-methodsigs");
912 // Do not enable the missing -dealloc check.
913 // '-analyzer-check-objc-missing-dealloc',
914 CmdArgs
.push_back("-analyzer-check-objc-unused-ivars");
915 CmdArgs
.push_back("-analyzer-check-idempotent-operations");
918 // Set the output format. The default is plist, for (lame) historical
920 CmdArgs
.push_back("-analyzer-output");
921 if (Arg
*A
= Args
.getLastArg(options::OPT__analyzer_output
))
922 CmdArgs
.push_back(A
->getValue(Args
));
924 CmdArgs
.push_back("plist");
926 // Disable the presentation of standard compiler warnings when
927 // using --analyze. We only want to show static analyzer diagnostics
928 // or frontend errors.
929 CmdArgs
.push_back("-w");
931 // Add -Xanalyzer arguments when running as analyzer.
932 Args
.AddAllArgValues(CmdArgs
, options::OPT_Xanalyzer
);
935 CheckCodeGenerationOptions(D
, Args
);
937 // Perform argument translation for LLVM backend. This
938 // takes some care in reconciling with llvm-gcc. The
939 // issue is that llvm-gcc translates these options based on
940 // the values in cc1, whereas we are processing based on
941 // the driver arguments.
943 // This comes from the default translation the driver + cc1
944 // would do to enable flag_pic.
946 // FIXME: Centralize this code.
947 bool PICEnabled
= (Args
.hasArg(options::OPT_fPIC
) ||
948 Args
.hasArg(options::OPT_fpic
) ||
949 Args
.hasArg(options::OPT_fPIE
) ||
950 Args
.hasArg(options::OPT_fpie
));
951 bool PICDisabled
= (Args
.hasArg(options::OPT_mkernel
) ||
952 Args
.hasArg(options::OPT_static
));
953 const char *Model
= getToolChain().GetForcedPicModel();
955 if (Args
.hasArg(options::OPT_mdynamic_no_pic
))
956 Model
= "dynamic-no-pic";
957 else if (PICDisabled
)
962 Model
= getToolChain().GetDefaultRelocationModel();
964 if (llvm::StringRef(Model
) != "pic") {
965 CmdArgs
.push_back("-mrelocation-model");
966 CmdArgs
.push_back(Model
);
969 // Infer the __PIC__ value.
971 // FIXME: This isn't quite right on Darwin, which always sets
973 if (strcmp(Model
, "pic") == 0 || strcmp(Model
, "dynamic-no-pic") == 0) {
974 CmdArgs
.push_back("-pic-level");
975 CmdArgs
.push_back(Args
.hasArg(options::OPT_fPIC
) ? "2" : "1");
977 if (!Args
.hasFlag(options::OPT_fmerge_all_constants
,
978 options::OPT_fno_merge_all_constants
))
979 CmdArgs
.push_back("-no-merge-all-constants");
981 // LLVM Code Generator Options.
983 // FIXME: Set --enable-unsafe-fp-math.
984 if (Args
.hasFlag(options::OPT_fno_omit_frame_pointer
,
985 options::OPT_fomit_frame_pointer
))
986 CmdArgs
.push_back("-mdisable-fp-elim");
987 if (!Args
.hasFlag(options::OPT_fzero_initialized_in_bss
,
988 options::OPT_fno_zero_initialized_in_bss
))
989 CmdArgs
.push_back("-mno-zero-initialized-in-bss");
990 if (Args
.hasFlag(options::OPT_fno_strict_aliasing
,
991 options::OPT_fstrict_aliasing
,
993 CmdArgs
.push_back("-relaxed-aliasing");
995 // Decide whether to use verbose asm. Verbose assembly is the default on
996 // toolchains which have the integrated assembler on by default.
997 bool IsVerboseAsmDefault
= getToolChain().IsIntegratedAssemblerDefault();
998 if (Args
.hasFlag(options::OPT_fverbose_asm
, options::OPT_fno_verbose_asm
,
999 IsVerboseAsmDefault
) ||
1000 Args
.hasArg(options::OPT_dA
))
1001 CmdArgs
.push_back("-masm-verbose");
1003 if (Args
.hasArg(options::OPT_fdebug_pass_structure
)) {
1004 CmdArgs
.push_back("-mdebug-pass");
1005 CmdArgs
.push_back("Structure");
1007 if (Args
.hasArg(options::OPT_fdebug_pass_arguments
)) {
1008 CmdArgs
.push_back("-mdebug-pass");
1009 CmdArgs
.push_back("Arguments");
1012 // Enable -mconstructor-aliases except on darwin, where we have to
1013 // work around a linker bug; see <rdar://problem/7651567>.
1014 if (getToolChain().getTriple().getOS() != llvm::Triple::Darwin
)
1015 CmdArgs
.push_back("-mconstructor-aliases");
1017 // This is a coarse approximation of what llvm-gcc actually does, both
1018 // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
1019 // complicated ways.
1020 bool AsynchronousUnwindTables
=
1021 Args
.hasFlag(options::OPT_fasynchronous_unwind_tables
,
1022 options::OPT_fno_asynchronous_unwind_tables
,
1023 getToolChain().IsUnwindTablesDefault() &&
1025 if (Args
.hasFlag(options::OPT_funwind_tables
, options::OPT_fno_unwind_tables
,
1026 AsynchronousUnwindTables
))
1027 CmdArgs
.push_back("-munwind-tables");
1029 if (Arg
*A
= Args
.getLastArg(options::OPT_flimited_precision_EQ
)) {
1030 CmdArgs
.push_back("-mlimit-float-precision");
1031 CmdArgs
.push_back(A
->getValue(Args
));
1034 // FIXME: Handle -mtune=.
1035 (void) Args
.hasArg(options::OPT_mtune_EQ
);
1037 if (Arg
*A
= Args
.getLastArg(options::OPT_mcmodel_EQ
)) {
1038 CmdArgs
.push_back("-mcode-model");
1039 CmdArgs
.push_back(A
->getValue(Args
));
1042 // Add target specific cpu and features flags.
1043 switch(getToolChain().getTriple().getArch()) {
1047 case llvm::Triple::arm
:
1048 case llvm::Triple::thumb
:
1049 AddARMTargetArgs(Args
, CmdArgs
);
1052 case llvm::Triple::mips
:
1053 case llvm::Triple::mipsel
:
1054 AddMIPSTargetArgs(Args
, CmdArgs
);
1057 case llvm::Triple::sparc
:
1058 AddSparcTargetArgs(Args
, CmdArgs
);
1061 case llvm::Triple::x86
:
1062 case llvm::Triple::x86_64
:
1063 AddX86TargetArgs(Args
, CmdArgs
);
1067 // Pass the linker version in use.
1068 if (Arg
*A
= Args
.getLastArg(options::OPT_mlinker_version_EQ
)) {
1069 CmdArgs
.push_back("-target-linker-version");
1070 CmdArgs
.push_back(A
->getValue(Args
));
1073 // -mno-omit-leaf-frame-pointer is default.
1074 if (Args
.hasFlag(options::OPT_momit_leaf_frame_pointer
,
1075 options::OPT_mno_omit_leaf_frame_pointer
, false))
1076 CmdArgs
.push_back("-momit-leaf-frame-pointer");
1078 // -fno-math-errno is default.
1079 if (Args
.hasFlag(options::OPT_fmath_errno
,
1080 options::OPT_fno_math_errno
,
1082 CmdArgs
.push_back("-fmath-errno");
1084 // Explicitly error on some things we know we don't support and can't just
1086 types::ID InputType
= Inputs
[0].getType();
1087 if (!Args
.hasArg(options::OPT_fallow_unsupported
)) {
1089 if ((Unsupported
= Args
.getLastArg(options::OPT_MG
)) ||
1090 (Unsupported
= Args
.getLastArg(options::OPT_iframework
)))
1091 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1092 << Unsupported
->getOption().getName();
1094 if (types::isCXX(InputType
) &&
1095 getToolChain().getTriple().getOS() == llvm::Triple::Darwin
&&
1096 getToolChain().getTriple().getArch() == llvm::Triple::x86
) {
1097 if ((Unsupported
= Args
.getLastArg(options::OPT_fapple_kext
)))
1098 D
.Diag(clang::diag::err_drv_clang_unsupported_opt_cxx_darwin_i386
)
1099 << Unsupported
->getOption().getName();
1103 Args
.AddAllArgs(CmdArgs
, options::OPT_v
);
1104 Args
.AddLastArg(CmdArgs
, options::OPT_H
);
1105 Args
.AddLastArg(CmdArgs
, options::OPT_P
);
1106 Args
.AddLastArg(CmdArgs
, options::OPT_print_ivar_layout
);
1108 // Special case debug options to only pass -g to clang. This is
1110 Args
.ClaimAllArgs(options::OPT_g_Group
);
1111 if (Arg
*A
= Args
.getLastArg(options::OPT_g_Group
))
1112 if (!A
->getOption().matches(options::OPT_g0
))
1113 CmdArgs
.push_back("-g");
1115 Args
.AddAllArgs(CmdArgs
, options::OPT_ffunction_sections
);
1116 Args
.AddAllArgs(CmdArgs
, options::OPT_fdata_sections
);
1118 Args
.AddAllArgs(CmdArgs
, options::OPT_finstrument_functions
);
1120 Args
.AddLastArg(CmdArgs
, options::OPT_nostdinc
);
1121 Args
.AddLastArg(CmdArgs
, options::OPT_nostdincxx
);
1122 Args
.AddLastArg(CmdArgs
, options::OPT_nobuiltininc
);
1124 // Pass the path to compiler resource files.
1125 CmdArgs
.push_back("-resource-dir");
1126 CmdArgs
.push_back(D
.ResourceDir
.c_str());
1128 Args
.AddLastArg(CmdArgs
, options::OPT_working_directory
);
1130 // Add preprocessing options like -I, -D, etc. if we are using the
1133 // FIXME: Support -fpreprocessed
1134 if (types::getPreprocessedType(InputType
) != types::TY_INVALID
)
1135 AddPreprocessingOptions(D
, Args
, CmdArgs
, Output
, Inputs
);
1137 // Manually translate -O to -O2 and -O4 to -O3; let clang reject
1139 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
)) {
1140 if (A
->getOption().matches(options::OPT_O4
))
1141 CmdArgs
.push_back("-O3");
1142 else if (A
->getOption().matches(options::OPT_O
) &&
1143 A
->getValue(Args
)[0] == '\0')
1144 CmdArgs
.push_back("-O2");
1145 else if (A
->getOption().matches(options::OPT_O
) &&
1146 A
->getValue(Args
)[0] == 'z' &&
1147 A
->getValue(Args
)[1] == '\0')
1148 CmdArgs
.push_back("-Os");
1150 A
->render(Args
, CmdArgs
);
1153 // Silence warning for "clang -O2 -O0 -c foo.c -o foo.o"
1154 Args
.ClaimAllArgs(options::OPT_O_Group
);
1156 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
);
1157 Args
.AddLastArg(CmdArgs
, options::OPT_pedantic
);
1158 Args
.AddLastArg(CmdArgs
, options::OPT_pedantic_errors
);
1159 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
1161 // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi}
1162 // (-ansi is equivalent to -std=c89).
1164 // If a std is supplied, only add -trigraphs if it follows the
1166 if (Arg
*Std
= Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
1167 if (Std
->getOption().matches(options::OPT_ansi
))
1168 if (types::isCXX(InputType
))
1169 CmdArgs
.push_back("-std=c++98");
1171 CmdArgs
.push_back("-std=c89");
1173 Std
->render(Args
, CmdArgs
);
1175 if (Arg
*A
= Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
,
1176 options::OPT_trigraphs
))
1178 A
->render(Args
, CmdArgs
);
1180 // Honor -std-default.
1182 // FIXME: Clang doesn't correctly handle -std= when the input language
1183 // doesn't match. For the time being just ignore this for C++ inputs;
1184 // eventually we want to do all the standard defaulting here instead of
1185 // splitting it between the driver and clang -cc1.
1186 if (!types::isCXX(InputType
))
1187 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
1188 "-std=", /*Joined=*/true);
1189 Args
.AddLastArg(CmdArgs
, options::OPT_trigraphs
);
1192 // Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'.
1193 if (Arg
*Asm
= Args
.getLastArg(options::OPT_fasm
, options::OPT_fno_asm
)) {
1194 if (Asm
->getOption().matches(options::OPT_fasm
))
1195 CmdArgs
.push_back("-fgnu-keywords");
1197 CmdArgs
.push_back("-fno-gnu-keywords");
1200 if (Arg
*A
= Args
.getLastArg(options::OPT_ftemplate_depth_
)) {
1201 CmdArgs
.push_back("-ftemplate-depth");
1202 CmdArgs
.push_back(A
->getValue(Args
));
1205 if (Arg
*A
= Args
.getLastArg(options::OPT_Wlarge_by_value_copy_EQ
,
1206 options::OPT_Wlarge_by_value_copy_def
)) {
1207 CmdArgs
.push_back("-Wlarge-by-value-copy");
1208 if (A
->getNumValues())
1209 CmdArgs
.push_back(A
->getValue(Args
));
1211 CmdArgs
.push_back("64"); // default value for -Wlarge-by-value-copy.
1214 if (Args
.hasArg(options::OPT__relocatable_pch
))
1215 CmdArgs
.push_back("-relocatable-pch");
1217 if (Arg
*A
= Args
.getLastArg(options::OPT_fconstant_string_class_EQ
)) {
1218 CmdArgs
.push_back("-fconstant-string-class");
1219 CmdArgs
.push_back(A
->getValue(Args
));
1222 if (Arg
*A
= Args
.getLastArg(options::OPT_ftabstop_EQ
)) {
1223 CmdArgs
.push_back("-ftabstop");
1224 CmdArgs
.push_back(A
->getValue(Args
));
1227 CmdArgs
.push_back("-ferror-limit");
1228 if (Arg
*A
= Args
.getLastArg(options::OPT_ferror_limit_EQ
))
1229 CmdArgs
.push_back(A
->getValue(Args
));
1231 CmdArgs
.push_back("19");
1233 if (Arg
*A
= Args
.getLastArg(options::OPT_fmacro_backtrace_limit_EQ
)) {
1234 CmdArgs
.push_back("-fmacro-backtrace-limit");
1235 CmdArgs
.push_back(A
->getValue(Args
));
1238 if (Arg
*A
= Args
.getLastArg(options::OPT_ftemplate_backtrace_limit_EQ
)) {
1239 CmdArgs
.push_back("-ftemplate-backtrace-limit");
1240 CmdArgs
.push_back(A
->getValue(Args
));
1243 // Pass -fmessage-length=.
1244 CmdArgs
.push_back("-fmessage-length");
1245 if (Arg
*A
= Args
.getLastArg(options::OPT_fmessage_length_EQ
)) {
1246 CmdArgs
.push_back(A
->getValue(Args
));
1248 // If -fmessage-length=N was not specified, determine whether this is a
1249 // terminal and, if so, implicitly define -fmessage-length appropriately.
1250 unsigned N
= llvm::sys::Process::StandardErrColumns();
1251 CmdArgs
.push_back(Args
.MakeArgString(llvm::Twine(N
)));
1254 if (const Arg
*A
= Args
.getLastArg(options::OPT_fvisibility_EQ
)) {
1255 CmdArgs
.push_back("-fvisibility");
1256 CmdArgs
.push_back(A
->getValue(Args
));
1259 Args
.AddLastArg(CmdArgs
, options::OPT_fvisibility_inlines_hidden
);
1261 // -fhosted is default.
1262 if (KernelOrKext
|| Args
.hasFlag(options::OPT_ffreestanding
,
1263 options::OPT_fhosted
,
1265 CmdArgs
.push_back("-ffreestanding");
1267 // Forward -f (flag) options which we can pass directly.
1268 Args
.AddLastArg(CmdArgs
, options::OPT_fcatch_undefined_behavior
);
1269 Args
.AddLastArg(CmdArgs
, options::OPT_femit_all_decls
);
1270 Args
.AddLastArg(CmdArgs
, options::OPT_fheinous_gnu_extensions
);
1271 Args
.AddLastArg(CmdArgs
, options::OPT_flimit_debug_info
);
1273 // -flax-vector-conversions is default.
1274 if (!Args
.hasFlag(options::OPT_flax_vector_conversions
,
1275 options::OPT_fno_lax_vector_conversions
))
1276 CmdArgs
.push_back("-fno-lax-vector-conversions");
1278 // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only
1279 // takes precedence.
1280 const Arg
*GCArg
= Args
.getLastArg(options::OPT_fobjc_gc_only
);
1282 GCArg
= Args
.getLastArg(options::OPT_fobjc_gc
);
1284 if (getToolChain().SupportsObjCGC()) {
1285 GCArg
->render(Args
, CmdArgs
);
1287 // FIXME: We should move this to a hard error.
1288 D
.Diag(clang::diag::warn_drv_objc_gc_unsupported
)
1289 << GCArg
->getAsString(Args
);
1293 Args
.AddLastArg(CmdArgs
, options::OPT_fno_show_column
);
1294 Args
.AddLastArg(CmdArgs
, options::OPT_fobjc_sender_dependent_dispatch
);
1295 Args
.AddLastArg(CmdArgs
, options::OPT_fdiagnostics_print_source_range_info
);
1296 Args
.AddLastArg(CmdArgs
, options::OPT_fdiagnostics_parseable_fixits
);
1297 Args
.AddLastArg(CmdArgs
, options::OPT_ftime_report
);
1298 Args
.AddLastArg(CmdArgs
, options::OPT_ftrapv
);
1300 if (Arg
*A
= Args
.getLastArg(options::OPT_ftrapv_handler_EQ
)) {
1301 CmdArgs
.push_back("-ftrapv-handler");
1302 CmdArgs
.push_back(A
->getValue(Args
));
1305 Args
.AddLastArg(CmdArgs
, options::OPT_fwrapv
);
1306 Args
.AddLastArg(CmdArgs
, options::OPT_fwritable_strings
);
1307 Args
.AddLastArg(CmdArgs
, options::OPT_funroll_loops
);
1309 Args
.AddLastArg(CmdArgs
, options::OPT_pthread
);
1311 // -stack-protector=0 is default.
1312 unsigned StackProtectorLevel
= 0;
1313 if (Arg
*A
= Args
.getLastArg(options::OPT_fno_stack_protector
,
1314 options::OPT_fstack_protector_all
,
1315 options::OPT_fstack_protector
)) {
1316 if (A
->getOption().matches(options::OPT_fstack_protector
))
1317 StackProtectorLevel
= 1;
1318 else if (A
->getOption().matches(options::OPT_fstack_protector_all
))
1319 StackProtectorLevel
= 2;
1321 StackProtectorLevel
= getToolChain().GetDefaultStackProtectorLevel();
1322 if (StackProtectorLevel
) {
1323 CmdArgs
.push_back("-stack-protector");
1324 CmdArgs
.push_back(Args
.MakeArgString(llvm::Twine(StackProtectorLevel
)));
1327 // Forward -f options with positive and negative forms; we translate
1330 // -fbuiltin is default.
1331 if (!Args
.hasFlag(options::OPT_fbuiltin
, options::OPT_fno_builtin
))
1332 CmdArgs
.push_back("-fno-builtin");
1334 if (!Args
.hasFlag(options::OPT_fassume_sane_operator_new
,
1335 options::OPT_fno_assume_sane_operator_new
))
1336 CmdArgs
.push_back("-fno-assume-sane-operator-new");
1338 // -fblocks=0 is default.
1339 if (Args
.hasFlag(options::OPT_fblocks
, options::OPT_fno_blocks
,
1340 getToolChain().IsBlocksDefault())) {
1341 CmdArgs
.push_back("-fblocks");
1344 // -faccess-control is default.
1345 if (Args
.hasFlag(options::OPT_fno_access_control
,
1346 options::OPT_faccess_control
,
1348 CmdArgs
.push_back("-fno-access-control");
1350 // -felide-constructors is the default.
1351 if (Args
.hasFlag(options::OPT_fno_elide_constructors
,
1352 options::OPT_felide_constructors
,
1354 CmdArgs
.push_back("-fno-elide-constructors");
1356 // -fexceptions=0 is default.
1357 if (!KernelOrKext
&&
1358 needsExceptions(Args
, InputType
, getToolChain().getTriple()))
1359 CmdArgs
.push_back("-fexceptions");
1361 if (getToolChain().UseSjLjExceptions())
1362 CmdArgs
.push_back("-fsjlj-exceptions");
1364 // -frtti is default.
1366 !Args
.hasFlag(options::OPT_frtti
, options::OPT_fno_rtti
))
1367 CmdArgs
.push_back("-fno-rtti");
1369 // -fshort-enums=0 is default.
1370 // FIXME: Are there targers where -fshort-enums is on by default ?
1371 if (Args
.hasFlag(options::OPT_fshort_enums
,
1372 options::OPT_fno_short_enums
, false))
1373 CmdArgs
.push_back("-fshort-enums");
1375 // -fsigned-char is default.
1376 if (!Args
.hasFlag(options::OPT_fsigned_char
, options::OPT_funsigned_char
,
1377 isSignedCharDefault(getToolChain().getTriple())))
1378 CmdArgs
.push_back("-fno-signed-char");
1380 // -fthreadsafe-static is default.
1381 if (!Args
.hasFlag(options::OPT_fthreadsafe_statics
,
1382 options::OPT_fno_threadsafe_statics
))
1383 CmdArgs
.push_back("-fno-threadsafe-statics");
1385 // -fuse-cxa-atexit is default.
1387 !Args
.hasFlag(options::OPT_fuse_cxa_atexit
, options::OPT_fno_use_cxa_atexit
,
1388 getToolChain().getTriple().getOS() != llvm::Triple::Cygwin
&&
1389 getToolChain().getTriple().getOS() != llvm::Triple::MinGW32
&&
1390 getToolChain().getTriple().getOS() != llvm::Triple::MinGW64
))
1391 CmdArgs
.push_back("-fno-use-cxa-atexit");
1393 // -fms-extensions=0 is default.
1394 if (Args
.hasFlag(options::OPT_fms_extensions
, options::OPT_fno_ms_extensions
,
1395 getToolChain().getTriple().getOS() == llvm::Triple::Win32
))
1396 CmdArgs
.push_back("-fms-extensions");
1398 // -fmsc-version=1300 is default.
1399 if (Args
.hasFlag(options::OPT_fms_extensions
, options::OPT_fno_ms_extensions
,
1400 getToolChain().getTriple().getOS() == llvm::Triple::Win32
) ||
1401 Args
.hasArg(options::OPT_fmsc_version
)) {
1402 llvm::StringRef msc_ver
= Args
.getLastArgValue(options::OPT_fmsc_version
);
1403 if (msc_ver
.empty())
1404 CmdArgs
.push_back("-fmsc-version=1300");
1406 CmdArgs
.push_back(Args
.MakeArgString("-fmsc-version=" + msc_ver
));
1410 // -fborland-extensions=0 is default.
1411 if (Args
.hasFlag(options::OPT_fborland_extensions
,
1412 options::OPT_fno_borland_extensions
, false))
1413 CmdArgs
.push_back("-fborland-extensions");
1415 // -fgnu-keywords default varies depending on language; only pass if
1417 if (Arg
*A
= Args
.getLastArg(options::OPT_fgnu_keywords
,
1418 options::OPT_fno_gnu_keywords
))
1419 A
->render(Args
, CmdArgs
);
1421 // -fnext-runtime defaults to on Darwin and when rewriting Objective-C, and is
1422 // -the -cc1 default.
1423 bool NeXTRuntimeIsDefault
=
1424 IsRewriter
|| getToolChain().getTriple().getOS() == llvm::Triple::Darwin
;
1425 if (!Args
.hasFlag(options::OPT_fnext_runtime
, options::OPT_fgnu_runtime
,
1426 NeXTRuntimeIsDefault
))
1427 CmdArgs
.push_back("-fgnu-runtime");
1429 // -fobjc-nonfragile-abi=0 is default.
1430 if (types::isObjC(InputType
)) {
1431 // Compute the Objective-C ABI "version" to use. Version numbers are
1432 // slightly confusing for historical reasons:
1433 // 1 - Traditional "fragile" ABI
1434 // 2 - Non-fragile ABI, version 1
1435 // 3 - Non-fragile ABI, version 2
1436 unsigned Version
= 1;
1437 // If -fobjc-abi-version= is present, use that to set the version.
1438 if (Arg
*A
= Args
.getLastArg(options::OPT_fobjc_abi_version_EQ
)) {
1439 if (llvm::StringRef(A
->getValue(Args
)) == "1")
1441 else if (llvm::StringRef(A
->getValue(Args
)) == "2")
1443 else if (llvm::StringRef(A
->getValue(Args
)) == "3")
1446 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
1448 // Otherwise, determine if we are using the non-fragile ABI.
1449 if (Args
.hasFlag(options::OPT_fobjc_nonfragile_abi
,
1450 options::OPT_fno_objc_nonfragile_abi
,
1451 getToolChain().IsObjCNonFragileABIDefault())) {
1452 // Determine the non-fragile ABI version to use.
1453 #ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO
1454 unsigned NonFragileABIVersion
= 1;
1456 unsigned NonFragileABIVersion
= 2;
1459 if (Arg
*A
= Args
.getLastArg(
1460 options::OPT_fobjc_nonfragile_abi_version_EQ
)) {
1461 if (llvm::StringRef(A
->getValue(Args
)) == "1")
1462 NonFragileABIVersion
= 1;
1463 else if (llvm::StringRef(A
->getValue(Args
)) == "2")
1464 NonFragileABIVersion
= 2;
1466 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1467 << A
->getAsString(Args
);
1470 Version
= 1 + NonFragileABIVersion
;
1476 if (Version
== 2 || Version
== 3) {
1478 CmdArgs
.push_back("-fobjc-nonfragile-abi");
1480 CmdArgs
.push_back("-fobjc-nonfragile-abi2");
1482 // -fobjc-dispatch-method is only relevant with the nonfragile-abi, and
1483 // legacy is the default.
1484 if (!Args
.hasFlag(options::OPT_fobjc_legacy_dispatch
,
1485 options::OPT_fno_objc_legacy_dispatch
,
1486 getToolChain().IsObjCLegacyDispatchDefault())) {
1487 if (getToolChain().UseObjCMixedDispatch())
1488 CmdArgs
.push_back("-fobjc-dispatch-method=mixed");
1490 CmdArgs
.push_back("-fobjc-dispatch-method=non-legacy");
1495 if (!Args
.hasFlag(options::OPT_fassume_sane_operator_new
,
1496 options::OPT_fno_assume_sane_operator_new
))
1497 CmdArgs
.push_back("-fno-assume-sane-operator-new");
1499 // -fconstant-cfstrings is default, and may be subject to argument translation
1501 if (!Args
.hasFlag(options::OPT_fconstant_cfstrings
,
1502 options::OPT_fno_constant_cfstrings
) ||
1503 !Args
.hasFlag(options::OPT_mconstant_cfstrings
,
1504 options::OPT_mno_constant_cfstrings
))
1505 CmdArgs
.push_back("-fno-constant-cfstrings");
1507 // -fshort-wchar default varies depending on platform; only
1508 // pass if specified.
1509 if (Arg
*A
= Args
.getLastArg(options::OPT_fshort_wchar
))
1510 A
->render(Args
, CmdArgs
);
1512 // -fno-pascal-strings is default, only pass non-default. If the tool chain
1513 // happened to translate to -mpascal-strings, we want to back translate here.
1515 // FIXME: This is gross; that translation should be pulled from the
1517 if (Args
.hasFlag(options::OPT_fpascal_strings
,
1518 options::OPT_fno_pascal_strings
,
1520 Args
.hasFlag(options::OPT_mpascal_strings
,
1521 options::OPT_mno_pascal_strings
,
1523 CmdArgs
.push_back("-fpascal-strings");
1525 // -fcommon is default, only pass non-default.
1526 if (!Args
.hasFlag(options::OPT_fcommon
, options::OPT_fno_common
))
1527 CmdArgs
.push_back("-fno-common");
1529 // -fsigned-bitfields is default, and clang doesn't yet support
1530 // -funsigned-bitfields.
1531 if (!Args
.hasFlag(options::OPT_fsigned_bitfields
,
1532 options::OPT_funsigned_bitfields
))
1533 D
.Diag(clang::diag::warn_drv_clang_unsupported
)
1534 << Args
.getLastArg(options::OPT_funsigned_bitfields
)->getAsString(Args
);
1536 // -fsigned-bitfields is default, and clang doesn't support -fno-for-scope.
1537 if (!Args
.hasFlag(options::OPT_ffor_scope
,
1538 options::OPT_fno_for_scope
))
1539 D
.Diag(clang::diag::err_drv_clang_unsupported
)
1540 << Args
.getLastArg(options::OPT_fno_for_scope
)->getAsString(Args
);
1542 // -fcaret-diagnostics is default.
1543 if (!Args
.hasFlag(options::OPT_fcaret_diagnostics
,
1544 options::OPT_fno_caret_diagnostics
, true))
1545 CmdArgs
.push_back("-fno-caret-diagnostics");
1547 // -fdiagnostics-fixit-info is default, only pass non-default.
1548 if (!Args
.hasFlag(options::OPT_fdiagnostics_fixit_info
,
1549 options::OPT_fno_diagnostics_fixit_info
))
1550 CmdArgs
.push_back("-fno-diagnostics-fixit-info");
1552 // Enable -fdiagnostics-show-option by default.
1553 if (Args
.hasFlag(options::OPT_fdiagnostics_show_option
,
1554 options::OPT_fno_diagnostics_show_option
))
1555 CmdArgs
.push_back("-fdiagnostics-show-option");
1558 Args
.getLastArg(options::OPT_fdiagnostics_show_category_EQ
)) {
1559 CmdArgs
.push_back("-fdiagnostics-show-category");
1560 CmdArgs
.push_back(A
->getValue(Args
));
1563 // Color diagnostics are the default, unless the terminal doesn't support
1565 if (Args
.hasFlag(options::OPT_fcolor_diagnostics
,
1566 options::OPT_fno_color_diagnostics
,
1567 llvm::sys::Process::StandardErrHasColors()))
1568 CmdArgs
.push_back("-fcolor-diagnostics");
1570 if (!Args
.hasFlag(options::OPT_fshow_source_location
,
1571 options::OPT_fno_show_source_location
))
1572 CmdArgs
.push_back("-fno-show-source-location");
1574 if (!Args
.hasFlag(options::OPT_fspell_checking
,
1575 options::OPT_fno_spell_checking
))
1576 CmdArgs
.push_back("-fno-spell-checking");
1579 // Silently ignore -fasm-blocks for now.
1580 (void) Args
.hasFlag(options::OPT_fasm_blocks
, options::OPT_fno_asm_blocks
,
1583 if (Arg
*A
= Args
.getLastArg(options::OPT_fshow_overloads_EQ
))
1584 A
->render(Args
, CmdArgs
);
1586 // -fdollars-in-identifiers default varies depending on platform and
1587 // language; only pass if specified.
1588 if (Arg
*A
= Args
.getLastArg(options::OPT_fdollars_in_identifiers
,
1589 options::OPT_fno_dollars_in_identifiers
)) {
1590 if (A
->getOption().matches(options::OPT_fdollars_in_identifiers
))
1591 CmdArgs
.push_back("-fdollars-in-identifiers");
1593 CmdArgs
.push_back("-fno-dollars-in-identifiers");
1596 // -funit-at-a-time is default, and we don't support -fno-unit-at-a-time for
1597 // practical purposes.
1598 if (Arg
*A
= Args
.getLastArg(options::OPT_funit_at_a_time
,
1599 options::OPT_fno_unit_at_a_time
)) {
1600 if (A
->getOption().matches(options::OPT_fno_unit_at_a_time
))
1601 D
.Diag(clang::diag::warn_drv_clang_unsupported
) << A
->getAsString(Args
);
1604 // Default to -fno-builtin-str{cat,cpy} on Darwin for ARM.
1606 // FIXME: This is disabled until clang -cc1 supports -fno-builtin-foo. PR4941.
1608 if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin
&&
1609 (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
1610 getToolChain().getTriple().getArch() == llvm::Triple::thumb
)) {
1611 if (!Args
.hasArg(options::OPT_fbuiltin_strcat
))
1612 CmdArgs
.push_back("-fno-builtin-strcat");
1613 if (!Args
.hasArg(options::OPT_fbuiltin_strcpy
))
1614 CmdArgs
.push_back("-fno-builtin-strcpy");
1618 if (Arg
*A
= Args
.getLastArg(options::OPT_traditional
,
1619 options::OPT_traditional_cpp
))
1620 D
.Diag(clang::diag::err_drv_clang_unsupported
) << A
->getAsString(Args
);
1622 Args
.AddLastArg(CmdArgs
, options::OPT_dM
);
1623 Args
.AddLastArg(CmdArgs
, options::OPT_dD
);
1625 // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
1627 Args
.AddAllArgValues(CmdArgs
, options::OPT_Xclang
);
1628 for (arg_iterator it
= Args
.filtered_begin(options::OPT_mllvm
),
1629 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
1632 // We translate this by hand to the -cc1 argument, since nightly test uses
1633 // it and developers have been trained to spell it with -mllvm.
1634 if (llvm::StringRef((*it
)->getValue(Args
, 0)) == "-disable-llvm-optzns")
1635 CmdArgs
.push_back("-disable-llvm-optzns");
1637 (*it
)->render(Args
, CmdArgs
);
1640 if (Output
.getType() == types::TY_Dependencies
) {
1641 // Handled with other dependency code.
1642 } else if (Output
.isFilename()) {
1643 CmdArgs
.push_back("-o");
1644 CmdArgs
.push_back(Output
.getFilename());
1646 assert(Output
.isNothing() && "Invalid output.");
1649 for (InputInfoList::const_iterator
1650 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
1651 const InputInfo
&II
= *it
;
1652 CmdArgs
.push_back("-x");
1653 CmdArgs
.push_back(types::getTypeName(II
.getType()));
1654 if (II
.isFilename())
1655 CmdArgs
.push_back(II
.getFilename());
1657 II
.getInputArg().renderAsInput(Args
, CmdArgs
);
1660 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
1662 const char *Exec
= getToolChain().getDriver().getClangProgramPath();
1664 // Optionally embed the -cc1 level arguments into the debug info, for build
1666 if (getToolChain().UseDwarfDebugFlags()) {
1667 ArgStringList OriginalArgs
;
1668 for (ArgList::const_iterator it
= Args
.begin(),
1669 ie
= Args
.end(); it
!= ie
; ++it
)
1670 (*it
)->render(Args
, OriginalArgs
);
1672 llvm::SmallString
<256> Flags
;
1674 for (unsigned i
= 0, e
= OriginalArgs
.size(); i
!= e
; ++i
) {
1676 Flags
+= OriginalArgs
[i
];
1678 CmdArgs
.push_back("-dwarf-debug-flags");
1679 CmdArgs
.push_back(Args
.MakeArgString(Flags
.str()));
1682 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1684 // Explicitly warn that these options are unsupported, even though
1685 // we are allowing compilation to continue.
1686 for (arg_iterator it
= Args
.filtered_begin(options::OPT_pg
),
1687 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
1689 D
.Diag(clang::diag::warn_drv_clang_unsupported
) << (*it
)->getAsString(Args
);
1692 // Claim some arguments which clang supports automatically.
1694 // -fpch-preprocess is used with gcc to add a special marker in the output to
1695 // include the PCH file. Clang's PTH solution is completely transparent, so we
1696 // do not need to deal with it at all.
1697 Args
.ClaimAllArgs(options::OPT_fpch_preprocess
);
1699 // Claim some arguments which clang doesn't support, but we don't
1700 // care to warn the user about.
1701 Args
.ClaimAllArgs(options::OPT_clang_ignored_f_Group
);
1702 Args
.ClaimAllArgs(options::OPT_clang_ignored_m_Group
);
1705 void ClangAs::ConstructJob(Compilation
&C
, const JobAction
&JA
,
1706 const InputInfo
&Output
,
1707 const InputInfoList
&Inputs
,
1708 const ArgList
&Args
,
1709 const char *LinkingOutput
) const {
1710 ArgStringList CmdArgs
;
1712 assert(Inputs
.size() == 1 && "Unexpected number of inputs.");
1713 const InputInfo
&Input
= Inputs
[0];
1715 // Don't warn about "clang -w -c foo.s"
1716 Args
.ClaimAllArgs(options::OPT_w
);
1718 // Invoke ourselves in -cc1as mode.
1720 // FIXME: Implement custom jobs for internal actions.
1721 CmdArgs
.push_back("-cc1as");
1723 // Add the "effective" target triple.
1724 CmdArgs
.push_back("-triple");
1725 std::string TripleStr
= getToolChain().ComputeEffectiveClangTriple(Args
);
1726 CmdArgs
.push_back(Args
.MakeArgString(TripleStr
));
1728 // Set the output mode, we currently only expect to be used as a real
1730 CmdArgs
.push_back("-filetype");
1731 CmdArgs
.push_back("obj");
1733 // At -O0, we use -mrelax-all by default.
1735 if (Arg
*A
= Args
.getLastArg(options::OPT_O_Group
))
1736 IsOpt
= !A
->getOption().matches(options::OPT_O0
);
1737 if (Args
.hasFlag(options::OPT_mrelax_all
,
1738 options::OPT_mno_relax_all
,
1740 CmdArgs
.push_back("-relax-all");
1742 // FIXME: Add -force_cpusubtype_ALL support, once we have it.
1744 // FIXME: Add -g support, once we have it.
1746 // FIXME: Add -static support, once we have it.
1748 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
1749 options::OPT_Xassembler
);
1751 assert(Output
.isFilename() && "Unexpected lipo output.");
1752 CmdArgs
.push_back("-o");
1753 CmdArgs
.push_back(Output
.getFilename());
1755 assert(Input
.isFilename() && "Invalid input.");
1756 CmdArgs
.push_back(Input
.getFilename());
1758 const char *Exec
= getToolChain().getDriver().getClangProgramPath();
1759 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1762 void gcc::Common::ConstructJob(Compilation
&C
, const JobAction
&JA
,
1763 const InputInfo
&Output
,
1764 const InputInfoList
&Inputs
,
1765 const ArgList
&Args
,
1766 const char *LinkingOutput
) const {
1767 const Driver
&D
= getToolChain().getDriver();
1768 ArgStringList CmdArgs
;
1770 for (ArgList::const_iterator
1771 it
= Args
.begin(), ie
= Args
.end(); it
!= ie
; ++it
) {
1773 if (A
->getOption().hasForwardToGCC()) {
1774 // Don't forward any -g arguments to assembly steps.
1775 if (isa
<AssembleJobAction
>(JA
) &&
1776 A
->getOption().matches(options::OPT_g_Group
))
1779 // It is unfortunate that we have to claim here, as this means
1780 // we will basically never report anything interesting for
1781 // platforms using a generic gcc, even if we are just using gcc
1782 // to get to the assembler.
1784 A
->render(Args
, CmdArgs
);
1788 RenderExtraToolArgs(JA
, CmdArgs
);
1790 // If using a driver driver, force the arch.
1791 const std::string
&Arch
= getToolChain().getArchName();
1792 if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin
) {
1793 CmdArgs
.push_back("-arch");
1795 // FIXME: Remove these special cases.
1796 if (Arch
== "powerpc")
1797 CmdArgs
.push_back("ppc");
1798 else if (Arch
== "powerpc64")
1799 CmdArgs
.push_back("ppc64");
1801 CmdArgs
.push_back(Args
.MakeArgString(Arch
));
1804 // Try to force gcc to match the tool chain we want, if we recognize
1807 // FIXME: The triple class should directly provide the information we want
1809 if (Arch
== "i386" || Arch
== "powerpc")
1810 CmdArgs
.push_back("-m32");
1811 else if (Arch
== "x86_64" || Arch
== "powerpc64")
1812 CmdArgs
.push_back("-m64");
1814 if (Output
.isFilename()) {
1815 CmdArgs
.push_back("-o");
1816 CmdArgs
.push_back(Output
.getFilename());
1818 assert(Output
.isNothing() && "Unexpected output");
1819 CmdArgs
.push_back("-fsyntax-only");
1823 // Only pass -x if gcc will understand it; otherwise hope gcc
1824 // understands the suffix correctly. The main use case this would go
1825 // wrong in is for linker inputs if they happened to have an odd
1826 // suffix; really the only way to get this to happen is a command
1827 // like '-x foobar a.c' which will treat a.c like a linker input.
1829 // FIXME: For the linker case specifically, can we safely convert
1830 // inputs into '-Wl,' options?
1831 for (InputInfoList::const_iterator
1832 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
1833 const InputInfo
&II
= *it
;
1835 // Don't try to pass LLVM or AST inputs to a generic gcc.
1836 if (II
.getType() == types::TY_LLVM_IR
|| II
.getType() == types::TY_LTO_IR
||
1837 II
.getType() == types::TY_LLVM_BC
|| II
.getType() == types::TY_LTO_BC
)
1838 D
.Diag(clang::diag::err_drv_no_linker_llvm_support
)
1839 << getToolChain().getTripleString();
1840 else if (II
.getType() == types::TY_AST
)
1841 D
.Diag(clang::diag::err_drv_no_ast_support
)
1842 << getToolChain().getTripleString();
1844 if (types::canTypeBeUserSpecified(II
.getType())) {
1845 CmdArgs
.push_back("-x");
1846 CmdArgs
.push_back(types::getTypeName(II
.getType()));
1849 if (II
.isFilename())
1850 CmdArgs
.push_back(II
.getFilename());
1852 const Arg
&A
= II
.getInputArg();
1854 // Reverse translate some rewritten options.
1855 if (A
.getOption().matches(options::OPT_Z_reserved_lib_stdcxx
)) {
1856 CmdArgs
.push_back("-lstdc++");
1860 // Don't render as input, we need gcc to do the translations.
1861 A
.render(Args
, CmdArgs
);
1865 const char *GCCName
= getToolChain().getDriver().getCCCGenericGCCName().c_str();
1867 Args
.MakeArgString(getToolChain().GetProgramPath(GCCName
));
1868 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
1871 void gcc::Preprocess::RenderExtraToolArgs(const JobAction
&JA
,
1872 ArgStringList
&CmdArgs
) const {
1873 CmdArgs
.push_back("-E");
1876 void gcc::Precompile::RenderExtraToolArgs(const JobAction
&JA
,
1877 ArgStringList
&CmdArgs
) const {
1878 // The type is good enough.
1881 void gcc::Compile::RenderExtraToolArgs(const JobAction
&JA
,
1882 ArgStringList
&CmdArgs
) const {
1883 const Driver
&D
= getToolChain().getDriver();
1885 // If -flto, etc. are present then make sure not to force assembly output.
1886 if (JA
.getType() == types::TY_LLVM_IR
|| JA
.getType() == types::TY_LTO_IR
||
1887 JA
.getType() == types::TY_LLVM_BC
|| JA
.getType() == types::TY_LTO_BC
)
1888 CmdArgs
.push_back("-c");
1890 if (JA
.getType() != types::TY_PP_Asm
)
1891 D
.Diag(clang::diag::err_drv_invalid_gcc_output_type
)
1892 << getTypeName(JA
.getType());
1894 CmdArgs
.push_back("-S");
1898 void gcc::Assemble::RenderExtraToolArgs(const JobAction
&JA
,
1899 ArgStringList
&CmdArgs
) const {
1900 CmdArgs
.push_back("-c");
1903 void gcc::Link::RenderExtraToolArgs(const JobAction
&JA
,
1904 ArgStringList
&CmdArgs
) const {
1905 // The types are (hopefully) good enough.
1908 const char *darwin::CC1::getCC1Name(types::ID Type
) const {
1911 assert(0 && "Unexpected type for Darwin CC1 tool.");
1913 case types::TY_C
: case types::TY_CHeader
:
1914 case types::TY_PP_C
: case types::TY_PP_CHeader
:
1916 case types::TY_ObjC
: case types::TY_ObjCHeader
:
1917 case types::TY_PP_ObjC
: case types::TY_PP_ObjCHeader
:
1919 case types::TY_CXX
: case types::TY_CXXHeader
:
1920 case types::TY_PP_CXX
: case types::TY_PP_CXXHeader
:
1922 case types::TY_ObjCXX
: case types::TY_ObjCXXHeader
:
1923 case types::TY_PP_ObjCXX
: case types::TY_PP_ObjCXXHeader
:
1924 return "cc1objplus";
1928 const char *darwin::CC1::getBaseInputName(const ArgList
&Args
,
1929 const InputInfoList
&Inputs
) {
1930 llvm::sys::Path
P(Inputs
[0].getBaseInput());
1931 return Args
.MakeArgString(P
.getLast());
1934 const char *darwin::CC1::getBaseInputStem(const ArgList
&Args
,
1935 const InputInfoList
&Inputs
) {
1936 const char *Str
= getBaseInputName(Args
, Inputs
);
1938 if (const char *End
= strchr(Str
, '.'))
1939 return Args
.MakeArgString(std::string(Str
, End
));
1945 darwin::CC1::getDependencyFileName(const ArgList
&Args
,
1946 const InputInfoList
&Inputs
) {
1947 // FIXME: Think about this more.
1950 if (Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
)) {
1951 std::string
Str(OutputOpt
->getValue(Args
));
1953 Res
= Str
.substr(0, Str
.rfind('.'));
1955 Res
= darwin::CC1::getBaseInputStem(Args
, Inputs
);
1957 return Args
.MakeArgString(Res
+ ".d");
1960 void darwin::CC1::AddCC1Args(const ArgList
&Args
,
1961 ArgStringList
&CmdArgs
) const {
1962 const Driver
&D
= getToolChain().getDriver();
1964 CheckCodeGenerationOptions(D
, Args
);
1966 // Derived from cc1 spec.
1967 if (!Args
.hasArg(options::OPT_mkernel
) && !Args
.hasArg(options::OPT_static
) &&
1968 !Args
.hasArg(options::OPT_mdynamic_no_pic
))
1969 CmdArgs
.push_back("-fPIC");
1971 if (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
1972 getToolChain().getTriple().getArch() == llvm::Triple::thumb
) {
1973 if (!Args
.hasArg(options::OPT_fbuiltin_strcat
))
1974 CmdArgs
.push_back("-fno-builtin-strcat");
1975 if (!Args
.hasArg(options::OPT_fbuiltin_strcpy
))
1976 CmdArgs
.push_back("-fno-builtin-strcpy");
1979 // gcc has some code here to deal with when no -mmacosx-version-min
1980 // and no -miphoneos-version-min is present, but this never happens
1981 // due to tool chain specific argument translation.
1983 if (Args
.hasArg(options::OPT_g_Flag
) &&
1984 !Args
.hasArg(options::OPT_fno_eliminate_unused_debug_symbols
))
1985 CmdArgs
.push_back("-feliminate-unused-debug-symbols");
1988 void darwin::CC1::AddCC1OptionsArgs(const ArgList
&Args
, ArgStringList
&CmdArgs
,
1989 const InputInfoList
&Inputs
,
1990 const ArgStringList
&OutputArgs
) const {
1991 const Driver
&D
= getToolChain().getDriver();
1993 // Derived from cc1_options spec.
1994 if (Args
.hasArg(options::OPT_fast
) ||
1995 Args
.hasArg(options::OPT_fastf
) ||
1996 Args
.hasArg(options::OPT_fastcp
))
1997 CmdArgs
.push_back("-O3");
1999 if (Arg
*A
= Args
.getLastArg(options::OPT_pg
))
2000 if (Args
.hasArg(options::OPT_fomit_frame_pointer
))
2001 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
2002 << A
->getAsString(Args
) << "-fomit-frame-pointer";
2004 AddCC1Args(Args
, CmdArgs
);
2006 if (!Args
.hasArg(options::OPT_Q
))
2007 CmdArgs
.push_back("-quiet");
2009 CmdArgs
.push_back("-dumpbase");
2010 CmdArgs
.push_back(darwin::CC1::getBaseInputName(Args
, Inputs
));
2012 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Group
);
2014 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Group
);
2015 Args
.AddAllArgs(CmdArgs
, options::OPT_a_Group
);
2017 // FIXME: The goal is to use the user provided -o if that is our
2018 // final output, otherwise to drive from the original input
2019 // name. Find a clean way to go about this.
2020 if ((Args
.hasArg(options::OPT_c
) || Args
.hasArg(options::OPT_S
)) &&
2021 Args
.hasArg(options::OPT_o
)) {
2022 Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
);
2023 CmdArgs
.push_back("-auxbase-strip");
2024 CmdArgs
.push_back(OutputOpt
->getValue(Args
));
2026 CmdArgs
.push_back("-auxbase");
2027 CmdArgs
.push_back(darwin::CC1::getBaseInputStem(Args
, Inputs
));
2030 Args
.AddAllArgs(CmdArgs
, options::OPT_g_Group
);
2032 Args
.AddAllArgs(CmdArgs
, options::OPT_O
);
2033 // FIXME: -Wall is getting some special treatment. Investigate.
2034 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
, options::OPT_pedantic_Group
);
2035 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2036 Args
.AddAllArgs(CmdArgs
, options::OPT_std_EQ
, options::OPT_ansi
,
2037 options::OPT_trigraphs
);
2038 if (!Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
2039 // Honor -std-default.
2040 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
2041 "-std=", /*Joined=*/true);
2044 if (Args
.hasArg(options::OPT_v
))
2045 CmdArgs
.push_back("-version");
2046 if (Args
.hasArg(options::OPT_pg
))
2047 CmdArgs
.push_back("-p");
2048 Args
.AddLastArg(CmdArgs
, options::OPT_p
);
2050 // The driver treats -fsyntax-only specially.
2051 if (getToolChain().getTriple().getArch() == llvm::Triple::arm
||
2052 getToolChain().getTriple().getArch() == llvm::Triple::thumb
) {
2053 // Removes -fbuiltin-str{cat,cpy}; these aren't recognized by cc1 but are
2054 // used to inhibit the default -fno-builtin-str{cat,cpy}.
2056 // FIXME: Should we grow a better way to deal with "removing" args?
2057 for (arg_iterator it
= Args
.filtered_begin(options::OPT_f_Group
,
2058 options::OPT_fsyntax_only
),
2059 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
2060 if (!(*it
)->getOption().matches(options::OPT_fbuiltin_strcat
) &&
2061 !(*it
)->getOption().matches(options::OPT_fbuiltin_strcpy
)) {
2063 (*it
)->render(Args
, CmdArgs
);
2067 Args
.AddAllArgs(CmdArgs
, options::OPT_f_Group
, options::OPT_fsyntax_only
);
2069 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
2070 if (Args
.hasArg(options::OPT_Qn
))
2071 CmdArgs
.push_back("-fno-ident");
2073 // FIXME: This isn't correct.
2074 //Args.AddLastArg(CmdArgs, options::OPT__help)
2075 //Args.AddLastArg(CmdArgs, options::OPT__targetHelp)
2077 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2079 // FIXME: Still don't get what is happening here. Investigate.
2080 Args
.AddAllArgs(CmdArgs
, options::OPT__param
);
2082 if (Args
.hasArg(options::OPT_fmudflap
) ||
2083 Args
.hasArg(options::OPT_fmudflapth
)) {
2084 CmdArgs
.push_back("-fno-builtin");
2085 CmdArgs
.push_back("-fno-merge-constants");
2088 if (Args
.hasArg(options::OPT_coverage
)) {
2089 CmdArgs
.push_back("-fprofile-arcs");
2090 CmdArgs
.push_back("-ftest-coverage");
2093 if (types::isCXX(Inputs
[0].getType()))
2094 CmdArgs
.push_back("-D__private_extern__=extern");
2097 void darwin::CC1::AddCPPOptionsArgs(const ArgList
&Args
, ArgStringList
&CmdArgs
,
2098 const InputInfoList
&Inputs
,
2099 const ArgStringList
&OutputArgs
) const {
2100 // Derived from cpp_options
2101 AddCPPUniqueOptionsArgs(Args
, CmdArgs
, Inputs
);
2103 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2105 AddCC1Args(Args
, CmdArgs
);
2107 // NOTE: The code below has some commonality with cpp_options, but
2108 // in classic gcc style ends up sending things in different
2109 // orders. This may be a good merge candidate once we drop pedantic
2112 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Group
);
2113 Args
.AddAllArgs(CmdArgs
, options::OPT_std_EQ
, options::OPT_ansi
,
2114 options::OPT_trigraphs
);
2115 if (!Args
.getLastArg(options::OPT_std_EQ
, options::OPT_ansi
)) {
2116 // Honor -std-default.
2117 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_std_default_EQ
,
2118 "-std=", /*Joined=*/true);
2120 Args
.AddAllArgs(CmdArgs
, options::OPT_W_Group
, options::OPT_pedantic_Group
);
2121 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2123 // The driver treats -fsyntax-only specially.
2124 Args
.AddAllArgs(CmdArgs
, options::OPT_f_Group
, options::OPT_fsyntax_only
);
2126 if (Args
.hasArg(options::OPT_g_Group
) && !Args
.hasArg(options::OPT_g0
) &&
2127 !Args
.hasArg(options::OPT_fno_working_directory
))
2128 CmdArgs
.push_back("-fworking-directory");
2130 Args
.AddAllArgs(CmdArgs
, options::OPT_O
);
2131 Args
.AddAllArgs(CmdArgs
, options::OPT_undef
);
2132 if (Args
.hasArg(options::OPT_save_temps
))
2133 CmdArgs
.push_back("-fpch-preprocess");
2136 void darwin::CC1::AddCPPUniqueOptionsArgs(const ArgList
&Args
,
2137 ArgStringList
&CmdArgs
,
2138 const InputInfoList
&Inputs
) const {
2139 const Driver
&D
= getToolChain().getDriver();
2141 CheckPreprocessingOptions(D
, Args
);
2143 // Derived from cpp_unique_options.
2144 // -{C,CC} only with -E is checked in CheckPreprocessingOptions().
2145 Args
.AddLastArg(CmdArgs
, options::OPT_C
);
2146 Args
.AddLastArg(CmdArgs
, options::OPT_CC
);
2147 if (!Args
.hasArg(options::OPT_Q
))
2148 CmdArgs
.push_back("-quiet");
2149 Args
.AddAllArgs(CmdArgs
, options::OPT_nostdinc
);
2150 Args
.AddAllArgs(CmdArgs
, options::OPT_nostdincxx
);
2151 Args
.AddLastArg(CmdArgs
, options::OPT_v
);
2152 Args
.AddAllArgs(CmdArgs
, options::OPT_I_Group
, options::OPT_F
);
2153 Args
.AddLastArg(CmdArgs
, options::OPT_P
);
2155 // FIXME: Handle %I properly.
2156 if (getToolChain().getArchName() == "x86_64") {
2157 CmdArgs
.push_back("-imultilib");
2158 CmdArgs
.push_back("x86_64");
2161 if (Args
.hasArg(options::OPT_MD
)) {
2162 CmdArgs
.push_back("-MD");
2163 CmdArgs
.push_back(darwin::CC1::getDependencyFileName(Args
, Inputs
));
2166 if (Args
.hasArg(options::OPT_MMD
)) {
2167 CmdArgs
.push_back("-MMD");
2168 CmdArgs
.push_back(darwin::CC1::getDependencyFileName(Args
, Inputs
));
2171 Args
.AddLastArg(CmdArgs
, options::OPT_M
);
2172 Args
.AddLastArg(CmdArgs
, options::OPT_MM
);
2173 Args
.AddAllArgs(CmdArgs
, options::OPT_MF
);
2174 Args
.AddLastArg(CmdArgs
, options::OPT_MG
);
2175 Args
.AddLastArg(CmdArgs
, options::OPT_MP
);
2176 Args
.AddAllArgs(CmdArgs
, options::OPT_MQ
);
2177 Args
.AddAllArgs(CmdArgs
, options::OPT_MT
);
2178 if (!Args
.hasArg(options::OPT_M
) && !Args
.hasArg(options::OPT_MM
) &&
2179 (Args
.hasArg(options::OPT_MD
) || Args
.hasArg(options::OPT_MMD
))) {
2180 if (Arg
*OutputOpt
= Args
.getLastArg(options::OPT_o
)) {
2181 CmdArgs
.push_back("-MQ");
2182 CmdArgs
.push_back(OutputOpt
->getValue(Args
));
2186 Args
.AddLastArg(CmdArgs
, options::OPT_remap
);
2187 if (Args
.hasArg(options::OPT_g3
))
2188 CmdArgs
.push_back("-dD");
2189 Args
.AddLastArg(CmdArgs
, options::OPT_H
);
2191 AddCPPArgs(Args
, CmdArgs
);
2193 Args
.AddAllArgs(CmdArgs
, options::OPT_D
, options::OPT_U
, options::OPT_A
);
2194 Args
.AddAllArgs(CmdArgs
, options::OPT_i_Group
);
2196 for (InputInfoList::const_iterator
2197 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2198 const InputInfo
&II
= *it
;
2200 CmdArgs
.push_back(II
.getFilename());
2203 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wp_COMMA
,
2204 options::OPT_Xpreprocessor
);
2206 if (Args
.hasArg(options::OPT_fmudflap
)) {
2207 CmdArgs
.push_back("-D_MUDFLAP");
2208 CmdArgs
.push_back("-include");
2209 CmdArgs
.push_back("mf-runtime.h");
2212 if (Args
.hasArg(options::OPT_fmudflapth
)) {
2213 CmdArgs
.push_back("-D_MUDFLAP");
2214 CmdArgs
.push_back("-D_MUDFLAPTH");
2215 CmdArgs
.push_back("-include");
2216 CmdArgs
.push_back("mf-runtime.h");
2220 void darwin::CC1::AddCPPArgs(const ArgList
&Args
,
2221 ArgStringList
&CmdArgs
) const {
2222 // Derived from cpp spec.
2224 if (Args
.hasArg(options::OPT_static
)) {
2225 // The gcc spec is broken here, it refers to dynamic but
2226 // that has been translated. Start by being bug compatible.
2228 // if (!Args.hasArg(arglist.parser.dynamicOption))
2229 CmdArgs
.push_back("-D__STATIC__");
2231 CmdArgs
.push_back("-D__DYNAMIC__");
2233 if (Args
.hasArg(options::OPT_pthread
))
2234 CmdArgs
.push_back("-D_REENTRANT");
2237 void darwin::Preprocess::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2238 const InputInfo
&Output
,
2239 const InputInfoList
&Inputs
,
2240 const ArgList
&Args
,
2241 const char *LinkingOutput
) const {
2242 ArgStringList CmdArgs
;
2244 assert(Inputs
.size() == 1 && "Unexpected number of inputs!");
2246 CmdArgs
.push_back("-E");
2248 if (Args
.hasArg(options::OPT_traditional
) ||
2249 Args
.hasArg(options::OPT_traditional_cpp
))
2250 CmdArgs
.push_back("-traditional-cpp");
2252 ArgStringList OutputArgs
;
2253 assert(Output
.isFilename() && "Unexpected CC1 output.");
2254 OutputArgs
.push_back("-o");
2255 OutputArgs
.push_back(Output
.getFilename());
2257 if (Args
.hasArg(options::OPT_E
)) {
2258 AddCPPOptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2260 AddCPPOptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2261 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2264 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Group
);
2266 const char *CC1Name
= getCC1Name(Inputs
[0].getType());
2268 Args
.MakeArgString(getToolChain().GetProgramPath(CC1Name
));
2269 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2272 void darwin::Compile::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2273 const InputInfo
&Output
,
2274 const InputInfoList
&Inputs
,
2275 const ArgList
&Args
,
2276 const char *LinkingOutput
) const {
2277 const Driver
&D
= getToolChain().getDriver();
2278 ArgStringList CmdArgs
;
2280 assert(Inputs
.size() == 1 && "Unexpected number of inputs!");
2282 types::ID InputType
= Inputs
[0].getType();
2284 if ((A
= Args
.getLastArg(options::OPT_traditional
)))
2285 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
2286 << A
->getAsString(Args
) << "-E";
2288 if (JA
.getType() == types::TY_LLVM_IR
||
2289 JA
.getType() == types::TY_LTO_IR
)
2290 CmdArgs
.push_back("-emit-llvm");
2291 else if (JA
.getType() == types::TY_LLVM_BC
||
2292 JA
.getType() == types::TY_LTO_BC
)
2293 CmdArgs
.push_back("-emit-llvm-bc");
2294 else if (Output
.getType() == types::TY_AST
)
2295 D
.Diag(clang::diag::err_drv_no_ast_support
)
2296 << getToolChain().getTripleString();
2297 else if (JA
.getType() != types::TY_PP_Asm
&&
2298 JA
.getType() != types::TY_PCH
)
2299 D
.Diag(clang::diag::err_drv_invalid_gcc_output_type
)
2300 << getTypeName(JA
.getType());
2302 ArgStringList OutputArgs
;
2303 if (Output
.getType() != types::TY_PCH
) {
2304 OutputArgs
.push_back("-o");
2305 if (Output
.isNothing())
2306 OutputArgs
.push_back("/dev/null");
2308 OutputArgs
.push_back(Output
.getFilename());
2311 // There is no need for this level of compatibility, but it makes
2313 bool OutputArgsEarly
= (Args
.hasArg(options::OPT_fsyntax_only
) ||
2314 Args
.hasArg(options::OPT_S
));
2316 if (types::getPreprocessedType(InputType
) != types::TY_INVALID
) {
2317 AddCPPUniqueOptionsArgs(Args
, CmdArgs
, Inputs
);
2318 if (OutputArgsEarly
) {
2319 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2321 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2322 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2325 CmdArgs
.push_back("-fpreprocessed");
2327 for (InputInfoList::const_iterator
2328 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2329 const InputInfo
&II
= *it
;
2331 // Reject AST inputs.
2332 if (II
.getType() == types::TY_AST
) {
2333 D
.Diag(clang::diag::err_drv_no_ast_support
)
2334 << getToolChain().getTripleString();
2338 CmdArgs
.push_back(II
.getFilename());
2341 if (OutputArgsEarly
) {
2342 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, OutputArgs
);
2344 AddCC1OptionsArgs(Args
, CmdArgs
, Inputs
, ArgStringList());
2345 CmdArgs
.append(OutputArgs
.begin(), OutputArgs
.end());
2349 if (Output
.getType() == types::TY_PCH
) {
2350 assert(Output
.isFilename() && "Invalid PCH output.");
2352 CmdArgs
.push_back("-o");
2353 // NOTE: gcc uses a temp .s file for this, but there doesn't seem
2354 // to be a good reason.
2355 CmdArgs
.push_back("/dev/null");
2357 CmdArgs
.push_back("--output-pch=");
2358 CmdArgs
.push_back(Output
.getFilename());
2361 const char *CC1Name
= getCC1Name(Inputs
[0].getType());
2363 Args
.MakeArgString(getToolChain().GetProgramPath(CC1Name
));
2364 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2367 void darwin::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2368 const InputInfo
&Output
,
2369 const InputInfoList
&Inputs
,
2370 const ArgList
&Args
,
2371 const char *LinkingOutput
) const {
2372 ArgStringList CmdArgs
;
2374 assert(Inputs
.size() == 1 && "Unexpected number of inputs.");
2375 const InputInfo
&Input
= Inputs
[0];
2377 // Bit of a hack, this is only used for original inputs.
2379 // FIXME: This is broken for preprocessed .s inputs.
2380 if (Input
.isFilename() &&
2381 strcmp(Input
.getFilename(), Input
.getBaseInput()) == 0) {
2382 if (Args
.hasArg(options::OPT_gstabs
))
2383 CmdArgs
.push_back("--gstabs");
2384 else if (Args
.hasArg(options::OPT_g_Group
))
2385 CmdArgs
.push_back("--gdwarf2");
2388 // Derived from asm spec.
2389 AddDarwinArch(Args
, CmdArgs
);
2391 // Use -force_cpusubtype_ALL on x86 by default.
2392 if (getToolChain().getTriple().getArch() == llvm::Triple::x86
||
2393 getToolChain().getTriple().getArch() == llvm::Triple::x86_64
||
2394 Args
.hasArg(options::OPT_force__cpusubtype__ALL
))
2395 CmdArgs
.push_back("-force_cpusubtype_ALL");
2397 if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64
&&
2398 (Args
.hasArg(options::OPT_mkernel
) ||
2399 Args
.hasArg(options::OPT_static
) ||
2400 Args
.hasArg(options::OPT_fapple_kext
)))
2401 CmdArgs
.push_back("-static");
2403 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2404 options::OPT_Xassembler
);
2406 assert(Output
.isFilename() && "Unexpected lipo output.");
2407 CmdArgs
.push_back("-o");
2408 CmdArgs
.push_back(Output
.getFilename());
2410 assert(Input
.isFilename() && "Invalid input.");
2411 CmdArgs
.push_back(Input
.getFilename());
2413 // asm_final spec is empty.
2416 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
2417 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2420 void darwin::DarwinTool::AddDarwinArch(const ArgList
&Args
,
2421 ArgStringList
&CmdArgs
) const {
2422 llvm::StringRef ArchName
= getDarwinToolChain().getDarwinArchName(Args
);
2424 // Derived from darwin_arch spec.
2425 CmdArgs
.push_back("-arch");
2426 CmdArgs
.push_back(Args
.MakeArgString(ArchName
));
2428 // FIXME: Is this needed anymore?
2429 if (ArchName
== "arm")
2430 CmdArgs
.push_back("-force_cpusubtype_ALL");
2433 void darwin::Link::AddLinkArgs(Compilation
&C
,
2434 const ArgList
&Args
,
2435 ArgStringList
&CmdArgs
) const {
2436 const Driver
&D
= getToolChain().getDriver();
2438 unsigned Version
[3] = { 0, 0, 0 };
2439 if (Arg
*A
= Args
.getLastArg(options::OPT_mlinker_version_EQ
)) {
2441 if (!Driver::GetReleaseVersion(A
->getValue(Args
), Version
[0],
2442 Version
[1], Version
[2], HadExtra
) ||
2444 D
.Diag(clang::diag::err_drv_invalid_version_number
)
2445 << A
->getAsString(Args
);
2448 // Newer linkers support -demangle, pass it if supported and not disabled by
2451 // FIXME: We temporarily avoid passing -demangle to any iOS linker, because
2452 // unfortunately we can't be guaranteed that the linker version used there
2453 // will match the linker version detected at configure time. We need the
2454 // universal driver.
2455 if (Version
[0] >= 100 && !Args
.hasArg(options::OPT_Z_Xlinker__no_demangle
) &&
2456 !getDarwinToolChain().isTargetIPhoneOS()) {
2457 // Don't pass -demangle to ld_classic.
2459 // FIXME: This is a temporary workaround, ld should be handling this.
2460 bool UsesLdClassic
= (getToolChain().getArch() == llvm::Triple::x86
&&
2461 Args
.hasArg(options::OPT_static
));
2462 if (getToolChain().getArch() == llvm::Triple::x86
) {
2463 for (arg_iterator it
= Args
.filtered_begin(options::OPT_Xlinker
,
2464 options::OPT_Wl_COMMA
),
2465 ie
= Args
.filtered_end(); it
!= ie
; ++it
) {
2467 for (unsigned i
= 0, e
= A
->getNumValues(); i
!= e
; ++i
)
2468 if (llvm::StringRef(A
->getValue(Args
, i
)) == "-kext")
2469 UsesLdClassic
= true;
2473 CmdArgs
.push_back("-demangle");
2476 // Derived from the "link" spec.
2477 Args
.AddAllArgs(CmdArgs
, options::OPT_static
);
2478 if (!Args
.hasArg(options::OPT_static
))
2479 CmdArgs
.push_back("-dynamic");
2480 if (Args
.hasArg(options::OPT_fgnu_runtime
)) {
2481 // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu
2482 // here. How do we wish to handle such things?
2485 if (!Args
.hasArg(options::OPT_dynamiclib
)) {
2486 AddDarwinArch(Args
, CmdArgs
);
2487 // FIXME: Why do this only on this path?
2488 Args
.AddLastArg(CmdArgs
, options::OPT_force__cpusubtype__ALL
);
2490 Args
.AddLastArg(CmdArgs
, options::OPT_bundle
);
2491 Args
.AddAllArgs(CmdArgs
, options::OPT_bundle__loader
);
2492 Args
.AddAllArgs(CmdArgs
, options::OPT_client__name
);
2495 if ((A
= Args
.getLastArg(options::OPT_compatibility__version
)) ||
2496 (A
= Args
.getLastArg(options::OPT_current__version
)) ||
2497 (A
= Args
.getLastArg(options::OPT_install__name
)))
2498 D
.Diag(clang::diag::err_drv_argument_only_allowed_with
)
2499 << A
->getAsString(Args
) << "-dynamiclib";
2501 Args
.AddLastArg(CmdArgs
, options::OPT_force__flat__namespace
);
2502 Args
.AddLastArg(CmdArgs
, options::OPT_keep__private__externs
);
2503 Args
.AddLastArg(CmdArgs
, options::OPT_private__bundle
);
2505 CmdArgs
.push_back("-dylib");
2508 if ((A
= Args
.getLastArg(options::OPT_bundle
)) ||
2509 (A
= Args
.getLastArg(options::OPT_bundle__loader
)) ||
2510 (A
= Args
.getLastArg(options::OPT_client__name
)) ||
2511 (A
= Args
.getLastArg(options::OPT_force__flat__namespace
)) ||
2512 (A
= Args
.getLastArg(options::OPT_keep__private__externs
)) ||
2513 (A
= Args
.getLastArg(options::OPT_private__bundle
)))
2514 D
.Diag(clang::diag::err_drv_argument_not_allowed_with
)
2515 << A
->getAsString(Args
) << "-dynamiclib";
2517 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_compatibility__version
,
2518 "-dylib_compatibility_version");
2519 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_current__version
,
2520 "-dylib_current_version");
2522 AddDarwinArch(Args
, CmdArgs
);
2524 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_install__name
,
2525 "-dylib_install_name");
2528 Args
.AddLastArg(CmdArgs
, options::OPT_all__load
);
2529 Args
.AddAllArgs(CmdArgs
, options::OPT_allowable__client
);
2530 Args
.AddLastArg(CmdArgs
, options::OPT_bind__at__load
);
2531 if (getDarwinToolChain().isTargetIPhoneOS())
2532 Args
.AddLastArg(CmdArgs
, options::OPT_arch__errors__fatal
);
2533 Args
.AddLastArg(CmdArgs
, options::OPT_dead__strip
);
2534 Args
.AddLastArg(CmdArgs
, options::OPT_no__dead__strip__inits__and__terms
);
2535 Args
.AddAllArgs(CmdArgs
, options::OPT_dylib__file
);
2536 Args
.AddLastArg(CmdArgs
, options::OPT_dynamic
);
2537 Args
.AddAllArgs(CmdArgs
, options::OPT_exported__symbols__list
);
2538 Args
.AddLastArg(CmdArgs
, options::OPT_flat__namespace
);
2539 Args
.AddAllArgs(CmdArgs
, options::OPT_headerpad__max__install__names
);
2540 Args
.AddAllArgs(CmdArgs
, options::OPT_image__base
);
2541 Args
.AddAllArgs(CmdArgs
, options::OPT_init
);
2543 // Adding all arguments doesn't make sense here but this is what gcc does. One
2544 // of this should always be present thanks to argument translation.
2545 assert((Args
.hasArg(options::OPT_mmacosx_version_min_EQ
) ||
2546 Args
.hasArg(options::OPT_miphoneos_version_min_EQ
)) &&
2547 "Missing version argument (lost in translation)?");
2548 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_mmacosx_version_min_EQ
,
2549 "-macosx_version_min");
2550 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_miphoneos_version_min_EQ
,
2551 "-iphoneos_version_min");
2552 Args
.AddLastArg(CmdArgs
, options::OPT_nomultidefs
);
2553 Args
.AddLastArg(CmdArgs
, options::OPT_multi__module
);
2554 Args
.AddLastArg(CmdArgs
, options::OPT_single__module
);
2555 Args
.AddAllArgs(CmdArgs
, options::OPT_multiply__defined
);
2556 Args
.AddAllArgs(CmdArgs
, options::OPT_multiply__defined__unused
);
2558 if (const Arg
*A
= Args
.getLastArg(options::OPT_fpie
, options::OPT_fPIE
,
2559 options::OPT_fno_pie
,
2560 options::OPT_fno_PIE
)) {
2561 if (A
->getOption().matches(options::OPT_fpie
) ||
2562 A
->getOption().matches(options::OPT_fPIE
))
2563 CmdArgs
.push_back("-pie");
2565 CmdArgs
.push_back("-no_pie");
2568 Args
.AddLastArg(CmdArgs
, options::OPT_prebind
);
2569 Args
.AddLastArg(CmdArgs
, options::OPT_noprebind
);
2570 Args
.AddLastArg(CmdArgs
, options::OPT_nofixprebinding
);
2571 Args
.AddLastArg(CmdArgs
, options::OPT_prebind__all__twolevel__modules
);
2572 Args
.AddLastArg(CmdArgs
, options::OPT_read__only__relocs
);
2573 Args
.AddAllArgs(CmdArgs
, options::OPT_sectcreate
);
2574 Args
.AddAllArgs(CmdArgs
, options::OPT_sectorder
);
2575 Args
.AddAllArgs(CmdArgs
, options::OPT_seg1addr
);
2576 Args
.AddAllArgs(CmdArgs
, options::OPT_segprot
);
2577 Args
.AddAllArgs(CmdArgs
, options::OPT_segaddr
);
2578 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__only__addr
);
2579 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__write__addr
);
2580 Args
.AddAllArgs(CmdArgs
, options::OPT_seg__addr__table
);
2581 Args
.AddAllArgs(CmdArgs
, options::OPT_seg__addr__table__filename
);
2582 Args
.AddAllArgs(CmdArgs
, options::OPT_sub__library
);
2583 Args
.AddAllArgs(CmdArgs
, options::OPT_sub__umbrella
);
2585 Args
.AddAllArgsTranslated(CmdArgs
, options::OPT_isysroot
, "-syslibroot");
2586 if (getDarwinToolChain().isTargetIPhoneOS()) {
2587 if (!Args
.hasArg(options::OPT_isysroot
)) {
2588 CmdArgs
.push_back("-syslibroot");
2589 CmdArgs
.push_back("/Developer/SDKs/Extra");
2593 Args
.AddLastArg(CmdArgs
, options::OPT_twolevel__namespace
);
2594 Args
.AddLastArg(CmdArgs
, options::OPT_twolevel__namespace__hints
);
2595 Args
.AddAllArgs(CmdArgs
, options::OPT_umbrella
);
2596 Args
.AddAllArgs(CmdArgs
, options::OPT_undefined
);
2597 Args
.AddAllArgs(CmdArgs
, options::OPT_unexported__symbols__list
);
2598 Args
.AddAllArgs(CmdArgs
, options::OPT_weak__reference__mismatches
);
2599 Args
.AddLastArg(CmdArgs
, options::OPT_X_Flag
);
2600 Args
.AddAllArgs(CmdArgs
, options::OPT_y
);
2601 Args
.AddLastArg(CmdArgs
, options::OPT_w
);
2602 Args
.AddAllArgs(CmdArgs
, options::OPT_pagezero__size
);
2603 Args
.AddAllArgs(CmdArgs
, options::OPT_segs__read__
);
2604 Args
.AddLastArg(CmdArgs
, options::OPT_seglinkedit
);
2605 Args
.AddLastArg(CmdArgs
, options::OPT_noseglinkedit
);
2606 Args
.AddAllArgs(CmdArgs
, options::OPT_sectalign
);
2607 Args
.AddAllArgs(CmdArgs
, options::OPT_sectobjectsymbols
);
2608 Args
.AddAllArgs(CmdArgs
, options::OPT_segcreate
);
2609 Args
.AddLastArg(CmdArgs
, options::OPT_whyload
);
2610 Args
.AddLastArg(CmdArgs
, options::OPT_whatsloaded
);
2611 Args
.AddAllArgs(CmdArgs
, options::OPT_dylinker__install__name
);
2612 Args
.AddLastArg(CmdArgs
, options::OPT_dylinker
);
2613 Args
.AddLastArg(CmdArgs
, options::OPT_Mach
);
2616 void darwin::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2617 const InputInfo
&Output
,
2618 const InputInfoList
&Inputs
,
2619 const ArgList
&Args
,
2620 const char *LinkingOutput
) const {
2621 assert(Output
.getType() == types::TY_Image
&& "Invalid linker output type.");
2623 // The logic here is derived from gcc's behavior; most of which
2624 // comes from specs (starting with link_command). Consult gcc for
2625 // more information.
2626 ArgStringList CmdArgs
;
2628 // I'm not sure why this particular decomposition exists in gcc, but
2629 // we follow suite for ease of comparison.
2630 AddLinkArgs(C
, Args
, CmdArgs
);
2632 Args
.AddAllArgs(CmdArgs
, options::OPT_d_Flag
);
2633 Args
.AddAllArgs(CmdArgs
, options::OPT_s
);
2634 Args
.AddAllArgs(CmdArgs
, options::OPT_t
);
2635 Args
.AddAllArgs(CmdArgs
, options::OPT_Z_Flag
);
2636 Args
.AddAllArgs(CmdArgs
, options::OPT_u_Group
);
2637 Args
.AddAllArgs(CmdArgs
, options::OPT_A
);
2638 Args
.AddLastArg(CmdArgs
, options::OPT_e
);
2639 Args
.AddAllArgs(CmdArgs
, options::OPT_m_Separate
);
2640 Args
.AddAllArgs(CmdArgs
, options::OPT_r
);
2642 // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading
2643 // members of static archive libraries which implement Objective-C classes or
2645 if (Args
.hasArg(options::OPT_ObjC
) || Args
.hasArg(options::OPT_ObjCXX
))
2646 CmdArgs
.push_back("-ObjC");
2648 CmdArgs
.push_back("-o");
2649 CmdArgs
.push_back(Output
.getFilename());
2651 if (!Args
.hasArg(options::OPT_A
) &&
2652 !Args
.hasArg(options::OPT_nostdlib
) &&
2653 !Args
.hasArg(options::OPT_nostartfiles
)) {
2654 // Derived from startfile spec.
2655 if (Args
.hasArg(options::OPT_dynamiclib
)) {
2656 // Derived from darwin_dylib1 spec.
2657 if (getDarwinToolChain().isTargetIPhoneOS()) {
2658 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2659 CmdArgs
.push_back("-ldylib1.o");
2661 if (getDarwinToolChain().isMacosxVersionLT(10, 5))
2662 CmdArgs
.push_back("-ldylib1.o");
2663 else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2664 CmdArgs
.push_back("-ldylib1.10.5.o");
2667 if (Args
.hasArg(options::OPT_bundle
)) {
2668 if (!Args
.hasArg(options::OPT_static
)) {
2669 // Derived from darwin_bundle1 spec.
2670 if (getDarwinToolChain().isTargetIPhoneOS()) {
2671 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2672 CmdArgs
.push_back("-lbundle1.o");
2674 if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2675 CmdArgs
.push_back("-lbundle1.o");
2679 if (Args
.hasArg(options::OPT_pg
)) {
2680 if (Args
.hasArg(options::OPT_static
) ||
2681 Args
.hasArg(options::OPT_object
) ||
2682 Args
.hasArg(options::OPT_preload
)) {
2683 CmdArgs
.push_back("-lgcrt0.o");
2685 CmdArgs
.push_back("-lgcrt1.o");
2687 // darwin_crt2 spec is empty.
2690 if (Args
.hasArg(options::OPT_static
) ||
2691 Args
.hasArg(options::OPT_object
) ||
2692 Args
.hasArg(options::OPT_preload
)) {
2693 CmdArgs
.push_back("-lcrt0.o");
2695 // Derived from darwin_crt1 spec.
2696 if (getDarwinToolChain().isTargetIPhoneOS()) {
2697 if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
2698 CmdArgs
.push_back("-lcrt1.o");
2700 CmdArgs
.push_back("-lcrt1.3.1.o");
2702 if (getDarwinToolChain().isMacosxVersionLT(10, 5))
2703 CmdArgs
.push_back("-lcrt1.o");
2704 else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
2705 CmdArgs
.push_back("-lcrt1.10.5.o");
2707 CmdArgs
.push_back("-lcrt1.10.6.o");
2709 // darwin_crt2 spec is empty.
2716 if (!getDarwinToolChain().isTargetIPhoneOS() &&
2717 Args
.hasArg(options::OPT_shared_libgcc
) &&
2718 getDarwinToolChain().isMacosxVersionLT(10, 5)) {
2720 Args
.MakeArgString(getToolChain().GetFilePath("crt3.o"));
2721 CmdArgs
.push_back(Str
);
2725 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
2727 if (Args
.hasArg(options::OPT_fopenmp
))
2728 // This is more complicated in gcc...
2729 CmdArgs
.push_back("-lgomp");
2731 getDarwinToolChain().AddLinkSearchPathArgs(Args
, CmdArgs
);
2733 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
2735 if (LinkingOutput
) {
2736 CmdArgs
.push_back("-arch_multiple");
2737 CmdArgs
.push_back("-final_output");
2738 CmdArgs
.push_back(LinkingOutput
);
2741 if (Args
.hasArg(options::OPT_fprofile_arcs
) ||
2742 Args
.hasArg(options::OPT_fprofile_generate
) ||
2743 Args
.hasArg(options::OPT_fcreate_profile
) ||
2744 Args
.hasArg(options::OPT_coverage
))
2745 CmdArgs
.push_back("-lgcov");
2747 if (Args
.hasArg(options::OPT_fnested_functions
))
2748 CmdArgs
.push_back("-allow_stack_execute");
2750 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2751 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
2752 if (getToolChain().getDriver().CCCIsCXX
)
2753 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
2755 // link_ssp spec is empty.
2757 // Let the tool chain choose which runtime library to link.
2758 getDarwinToolChain().AddLinkRuntimeLibArgs(Args
, CmdArgs
);
2761 if (!Args
.hasArg(options::OPT_A
) &&
2762 !Args
.hasArg(options::OPT_nostdlib
) &&
2763 !Args
.hasArg(options::OPT_nostartfiles
)) {
2764 // endfile_spec is empty.
2767 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
2768 Args
.AddAllArgs(CmdArgs
, options::OPT_F
);
2771 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
2772 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2775 void darwin::Lipo::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2776 const InputInfo
&Output
,
2777 const InputInfoList
&Inputs
,
2778 const ArgList
&Args
,
2779 const char *LinkingOutput
) const {
2780 ArgStringList CmdArgs
;
2782 CmdArgs
.push_back("-create");
2783 assert(Output
.isFilename() && "Unexpected lipo output.");
2785 CmdArgs
.push_back("-output");
2786 CmdArgs
.push_back(Output
.getFilename());
2788 for (InputInfoList::const_iterator
2789 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2790 const InputInfo
&II
= *it
;
2791 assert(II
.isFilename() && "Unexpected lipo input.");
2792 CmdArgs
.push_back(II
.getFilename());
2795 Args
.MakeArgString(getToolChain().GetProgramPath("lipo"));
2796 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2799 void darwin::Dsymutil::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2800 const InputInfo
&Output
,
2801 const InputInfoList
&Inputs
,
2802 const ArgList
&Args
,
2803 const char *LinkingOutput
) const {
2804 ArgStringList CmdArgs
;
2806 assert(Inputs
.size() == 1 && "Unable to handle multiple inputs.");
2807 const InputInfo
&Input
= Inputs
[0];
2808 assert(Input
.isFilename() && "Unexpected dsymutil input.");
2809 CmdArgs
.push_back(Input
.getFilename());
2811 CmdArgs
.push_back("-o");
2812 CmdArgs
.push_back(Output
.getFilename());
2815 Args
.MakeArgString(getToolChain().GetProgramPath("dsymutil"));
2816 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2819 void auroraux::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2820 const InputInfo
&Output
,
2821 const InputInfoList
&Inputs
,
2822 const ArgList
&Args
,
2823 const char *LinkingOutput
) const {
2824 ArgStringList CmdArgs
;
2826 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2827 options::OPT_Xassembler
);
2829 CmdArgs
.push_back("-o");
2830 CmdArgs
.push_back(Output
.getFilename());
2832 for (InputInfoList::const_iterator
2833 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2834 const InputInfo
&II
= *it
;
2835 CmdArgs
.push_back(II
.getFilename());
2839 Args
.MakeArgString(getToolChain().GetProgramPath("gas"));
2840 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2843 void auroraux::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2844 const InputInfo
&Output
,
2845 const InputInfoList
&Inputs
,
2846 const ArgList
&Args
,
2847 const char *LinkingOutput
) const {
2848 ArgStringList CmdArgs
;
2850 if ((!Args
.hasArg(options::OPT_nostdlib
)) &&
2851 (!Args
.hasArg(options::OPT_shared
))) {
2852 CmdArgs
.push_back("-e");
2853 CmdArgs
.push_back("_start");
2856 if (Args
.hasArg(options::OPT_static
)) {
2857 CmdArgs
.push_back("-Bstatic");
2858 CmdArgs
.push_back("-dn");
2860 // CmdArgs.push_back("--eh-frame-hdr");
2861 CmdArgs
.push_back("-Bdynamic");
2862 if (Args
.hasArg(options::OPT_shared
)) {
2863 CmdArgs
.push_back("-shared");
2865 CmdArgs
.push_back("--dynamic-linker");
2866 CmdArgs
.push_back("/lib/ld.so.1"); // 64Bit Path /lib/amd64/ld.so.1
2870 if (Output
.isFilename()) {
2871 CmdArgs
.push_back("-o");
2872 CmdArgs
.push_back(Output
.getFilename());
2874 assert(Output
.isNothing() && "Invalid output.");
2877 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2878 !Args
.hasArg(options::OPT_nostartfiles
)) {
2879 if (!Args
.hasArg(options::OPT_shared
)) {
2880 CmdArgs
.push_back(Args
.MakeArgString(
2881 getToolChain().GetFilePath("crt1.o")));
2882 CmdArgs
.push_back(Args
.MakeArgString(
2883 getToolChain().GetFilePath("crti.o")));
2884 CmdArgs
.push_back(Args
.MakeArgString(
2885 getToolChain().GetFilePath("crtbegin.o")));
2887 CmdArgs
.push_back(Args
.MakeArgString(
2888 getToolChain().GetFilePath("crti.o")));
2890 CmdArgs
.push_back(Args
.MakeArgString(
2891 getToolChain().GetFilePath("crtn.o")));
2894 CmdArgs
.push_back(Args
.MakeArgString("-L/opt/gcc4/lib/gcc/"
2895 + getToolChain().getTripleString()
2898 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
2899 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
2900 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
2902 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
2904 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2905 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
2906 // FIXME: For some reason GCC passes -lgcc before adding
2907 // the default system libraries. Just mimic this for now.
2908 CmdArgs
.push_back("-lgcc");
2910 if (Args
.hasArg(options::OPT_pthread
))
2911 CmdArgs
.push_back("-pthread");
2912 if (!Args
.hasArg(options::OPT_shared
))
2913 CmdArgs
.push_back("-lc");
2914 CmdArgs
.push_back("-lgcc");
2917 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2918 !Args
.hasArg(options::OPT_nostartfiles
)) {
2919 if (!Args
.hasArg(options::OPT_shared
))
2920 CmdArgs
.push_back(Args
.MakeArgString(
2921 getToolChain().GetFilePath("crtend.o")));
2925 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
2926 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2929 void openbsd::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2930 const InputInfo
&Output
,
2931 const InputInfoList
&Inputs
,
2932 const ArgList
&Args
,
2933 const char *LinkingOutput
) const {
2934 ArgStringList CmdArgs
;
2936 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
2937 options::OPT_Xassembler
);
2939 CmdArgs
.push_back("-o");
2940 CmdArgs
.push_back(Output
.getFilename());
2942 for (InputInfoList::const_iterator
2943 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
2944 const InputInfo
&II
= *it
;
2945 CmdArgs
.push_back(II
.getFilename());
2949 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
2950 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
2953 void openbsd::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
2954 const InputInfo
&Output
,
2955 const InputInfoList
&Inputs
,
2956 const ArgList
&Args
,
2957 const char *LinkingOutput
) const {
2958 const Driver
&D
= getToolChain().getDriver();
2959 ArgStringList CmdArgs
;
2961 if ((!Args
.hasArg(options::OPT_nostdlib
)) &&
2962 (!Args
.hasArg(options::OPT_shared
))) {
2963 CmdArgs
.push_back("-e");
2964 CmdArgs
.push_back("__start");
2967 if (Args
.hasArg(options::OPT_static
)) {
2968 CmdArgs
.push_back("-Bstatic");
2970 if (Args
.hasArg(options::OPT_rdynamic
))
2971 CmdArgs
.push_back("-export-dynamic");
2972 CmdArgs
.push_back("--eh-frame-hdr");
2973 CmdArgs
.push_back("-Bdynamic");
2974 if (Args
.hasArg(options::OPT_shared
)) {
2975 CmdArgs
.push_back("-shared");
2977 CmdArgs
.push_back("-dynamic-linker");
2978 CmdArgs
.push_back("/usr/libexec/ld.so");
2982 if (Output
.isFilename()) {
2983 CmdArgs
.push_back("-o");
2984 CmdArgs
.push_back(Output
.getFilename());
2986 assert(Output
.isNothing() && "Invalid output.");
2989 if (!Args
.hasArg(options::OPT_nostdlib
) &&
2990 !Args
.hasArg(options::OPT_nostartfiles
)) {
2991 if (!Args
.hasArg(options::OPT_shared
)) {
2992 CmdArgs
.push_back(Args
.MakeArgString(
2993 getToolChain().GetFilePath("crt0.o")));
2994 CmdArgs
.push_back(Args
.MakeArgString(
2995 getToolChain().GetFilePath("crtbegin.o")));
2997 CmdArgs
.push_back(Args
.MakeArgString(
2998 getToolChain().GetFilePath("crtbeginS.o")));
3002 std::string Triple
= getToolChain().getTripleString();
3003 if (Triple
.substr(0, 6) == "x86_64")
3004 Triple
.replace(0, 6, "amd64");
3005 CmdArgs
.push_back(Args
.MakeArgString("-L/usr/lib/gcc-lib/" + Triple
+
3008 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3009 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3010 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3012 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3014 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3015 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3017 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3018 CmdArgs
.push_back("-lm");
3021 // FIXME: For some reason GCC passes -lgcc before adding
3022 // the default system libraries. Just mimic this for now.
3023 CmdArgs
.push_back("-lgcc");
3025 if (Args
.hasArg(options::OPT_pthread
))
3026 CmdArgs
.push_back("-pthread");
3027 if (!Args
.hasArg(options::OPT_shared
))
3028 CmdArgs
.push_back("-lc");
3029 CmdArgs
.push_back("-lgcc");
3032 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3033 !Args
.hasArg(options::OPT_nostartfiles
)) {
3034 if (!Args
.hasArg(options::OPT_shared
))
3035 CmdArgs
.push_back(Args
.MakeArgString(
3036 getToolChain().GetFilePath("crtend.o")));
3038 CmdArgs
.push_back(Args
.MakeArgString(
3039 getToolChain().GetFilePath("crtendS.o")));
3043 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3044 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3047 void freebsd::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3048 const InputInfo
&Output
,
3049 const InputInfoList
&Inputs
,
3050 const ArgList
&Args
,
3051 const char *LinkingOutput
) const {
3052 ArgStringList CmdArgs
;
3054 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
3055 // instruct as in the base system to assemble 32-bit code.
3056 if (getToolChain().getArchName() == "i386")
3057 CmdArgs
.push_back("--32");
3060 // Set byte order explicitly
3061 if (getToolChain().getArchName() == "mips")
3062 CmdArgs
.push_back("-EB");
3063 else if (getToolChain().getArchName() == "mipsel")
3064 CmdArgs
.push_back("-EL");
3066 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3067 options::OPT_Xassembler
);
3069 CmdArgs
.push_back("-o");
3070 CmdArgs
.push_back(Output
.getFilename());
3072 for (InputInfoList::const_iterator
3073 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3074 const InputInfo
&II
= *it
;
3075 CmdArgs
.push_back(II
.getFilename());
3079 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3080 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3083 void freebsd::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3084 const InputInfo
&Output
,
3085 const InputInfoList
&Inputs
,
3086 const ArgList
&Args
,
3087 const char *LinkingOutput
) const {
3088 const Driver
&D
= getToolChain().getDriver();
3089 ArgStringList CmdArgs
;
3091 if (Args
.hasArg(options::OPT_static
)) {
3092 CmdArgs
.push_back("-Bstatic");
3094 if (Args
.hasArg(options::OPT_rdynamic
))
3095 CmdArgs
.push_back("-export-dynamic");
3096 CmdArgs
.push_back("--eh-frame-hdr");
3097 if (Args
.hasArg(options::OPT_shared
)) {
3098 CmdArgs
.push_back("-Bshareable");
3100 CmdArgs
.push_back("-dynamic-linker");
3101 CmdArgs
.push_back("/libexec/ld-elf.so.1");
3105 // When building 32-bit code on FreeBSD/amd64, we have to explicitly
3106 // instruct ld in the base system to link 32-bit code.
3107 if (getToolChain().getArchName() == "i386") {
3108 CmdArgs
.push_back("-m");
3109 CmdArgs
.push_back("elf_i386_fbsd");
3112 if (Output
.isFilename()) {
3113 CmdArgs
.push_back("-o");
3114 CmdArgs
.push_back(Output
.getFilename());
3116 assert(Output
.isNothing() && "Invalid output.");
3119 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3120 !Args
.hasArg(options::OPT_nostartfiles
)) {
3121 if (!Args
.hasArg(options::OPT_shared
)) {
3122 CmdArgs
.push_back(Args
.MakeArgString(
3123 getToolChain().GetFilePath("crt1.o")));
3124 CmdArgs
.push_back(Args
.MakeArgString(
3125 getToolChain().GetFilePath("crti.o")));
3126 CmdArgs
.push_back(Args
.MakeArgString(
3127 getToolChain().GetFilePath("crtbegin.o")));
3129 CmdArgs
.push_back(Args
.MakeArgString(
3130 getToolChain().GetFilePath("crti.o")));
3131 CmdArgs
.push_back(Args
.MakeArgString(
3132 getToolChain().GetFilePath("crtbeginS.o")));
3136 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3137 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3138 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3139 Args
.AddAllArgs(CmdArgs
, options::OPT_s
);
3140 Args
.AddAllArgs(CmdArgs
, options::OPT_t
);
3141 Args
.AddAllArgs(CmdArgs
, options::OPT_Z_Flag
);
3142 Args
.AddAllArgs(CmdArgs
, options::OPT_r
);
3144 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3146 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3147 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3149 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3150 CmdArgs
.push_back("-lm");
3152 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
3153 // the default system libraries. Just mimic this for now.
3154 CmdArgs
.push_back("-lgcc");
3155 if (Args
.hasArg(options::OPT_static
)) {
3156 CmdArgs
.push_back("-lgcc_eh");
3158 CmdArgs
.push_back("--as-needed");
3159 CmdArgs
.push_back("-lgcc_s");
3160 CmdArgs
.push_back("--no-as-needed");
3163 if (Args
.hasArg(options::OPT_pthread
))
3164 CmdArgs
.push_back("-lpthread");
3165 CmdArgs
.push_back("-lc");
3167 CmdArgs
.push_back("-lgcc");
3168 if (Args
.hasArg(options::OPT_static
)) {
3169 CmdArgs
.push_back("-lgcc_eh");
3171 CmdArgs
.push_back("--as-needed");
3172 CmdArgs
.push_back("-lgcc_s");
3173 CmdArgs
.push_back("--no-as-needed");
3177 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3178 !Args
.hasArg(options::OPT_nostartfiles
)) {
3179 if (!Args
.hasArg(options::OPT_shared
))
3180 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3183 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3185 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3190 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3191 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3194 void linuxtools::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3195 const InputInfo
&Output
,
3196 const InputInfoList
&Inputs
,
3197 const ArgList
&Args
,
3198 const char *LinkingOutput
) const {
3199 ArgStringList CmdArgs
;
3201 // Add --32/--64 to make sure we get the format we want.
3202 // This is incomplete
3203 if (getToolChain().getArch() == llvm::Triple::x86
) {
3204 CmdArgs
.push_back("--32");
3205 } else if (getToolChain().getArch() == llvm::Triple::x86_64
) {
3206 CmdArgs
.push_back("--64");
3207 } else if (getToolChain().getArch() == llvm::Triple::arm
) {
3208 llvm::StringRef MArch
= getToolChain().getArchName();
3209 if (MArch
== "armv7" || MArch
== "armv7a" || MArch
== "armv7-a")
3210 CmdArgs
.push_back("-mfpu=neon");
3213 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3214 options::OPT_Xassembler
);
3216 CmdArgs
.push_back("-o");
3217 CmdArgs
.push_back(Output
.getFilename());
3219 for (InputInfoList::const_iterator
3220 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3221 const InputInfo
&II
= *it
;
3222 CmdArgs
.push_back(II
.getFilename());
3226 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3227 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3230 void linuxtools::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3231 const InputInfo
&Output
,
3232 const InputInfoList
&Inputs
,
3233 const ArgList
&Args
,
3234 const char *LinkingOutput
) const {
3235 const toolchains::Linux
& ToolChain
=
3236 static_cast<const toolchains::Linux
&>(getToolChain());
3237 const Driver
&D
= ToolChain
.getDriver();
3238 ArgStringList CmdArgs
;
3240 // Silence warning for "clang -g foo.o -o foo"
3241 Args
.ClaimAllArgs(options::OPT_g_Group
);
3242 // and for "clang -g foo.o -o foo". Other warning options are already
3243 // handled somewhere else.
3244 Args
.ClaimAllArgs(options::OPT_w
);
3246 if (Arg
*A
= Args
.getLastArg(options::OPT__sysroot_EQ
)) {
3247 CmdArgs
.push_back("--sysroot");
3248 CmdArgs
.push_back(A
->getValue(Args
));
3251 if (Args
.hasArg(options::OPT_pie
))
3252 CmdArgs
.push_back("-pie");
3254 if (Args
.hasArg(options::OPT_rdynamic
))
3255 CmdArgs
.push_back("-export-dynamic");
3257 if (Args
.hasArg(options::OPT_s
))
3258 CmdArgs
.push_back("-s");
3260 for (std::vector
<std::string
>::const_iterator i
= ToolChain
.ExtraOpts
.begin(),
3261 e
= ToolChain
.ExtraOpts
.end();
3263 CmdArgs
.push_back(i
->c_str());
3265 if (!Args
.hasArg(options::OPT_static
)) {
3266 CmdArgs
.push_back("--eh-frame-hdr");
3269 CmdArgs
.push_back("-m");
3270 if (ToolChain
.getArch() == llvm::Triple::x86
)
3271 CmdArgs
.push_back("elf_i386");
3272 else if (ToolChain
.getArch() == llvm::Triple::arm
)
3273 CmdArgs
.push_back("armelf_linux_eabi");
3275 CmdArgs
.push_back("elf_x86_64");
3277 if (Args
.hasArg(options::OPT_static
)) {
3278 if (ToolChain
.getArch() == llvm::Triple::arm
)
3279 CmdArgs
.push_back("-Bstatic");
3281 CmdArgs
.push_back("-static");
3282 } else if (Args
.hasArg(options::OPT_shared
)) {
3283 CmdArgs
.push_back("-shared");
3286 if (ToolChain
.getArch() == llvm::Triple::arm
||
3287 (!Args
.hasArg(options::OPT_static
) &&
3288 !Args
.hasArg(options::OPT_shared
))) {
3289 CmdArgs
.push_back("-dynamic-linker");
3290 if (ToolChain
.getArch() == llvm::Triple::x86
)
3291 CmdArgs
.push_back("/lib/ld-linux.so.2");
3292 else if (ToolChain
.getArch() == llvm::Triple::arm
)
3293 CmdArgs
.push_back("/lib/ld-linux.so.3");
3295 CmdArgs
.push_back("/lib64/ld-linux-x86-64.so.2");
3298 CmdArgs
.push_back("-o");
3299 CmdArgs
.push_back(Output
.getFilename());
3301 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3302 !Args
.hasArg(options::OPT_nostartfiles
)) {
3303 const char *crt1
= NULL
;
3304 if (!Args
.hasArg(options::OPT_shared
)){
3305 if (Args
.hasArg(options::OPT_pie
))
3311 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath(crt1
)));
3313 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath("crti.o")));
3315 const char *crtbegin
;
3316 if (Args
.hasArg(options::OPT_static
))
3317 crtbegin
= "crtbeginT.o";
3318 else if (Args
.hasArg(options::OPT_shared
) || Args
.hasArg(options::OPT_pie
))
3319 crtbegin
= "crtbeginS.o";
3321 crtbegin
= "crtbegin.o";
3322 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath(crtbegin
)));
3325 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3327 const ToolChain::path_list Paths
= ToolChain
.getFilePaths();
3329 for (ToolChain::path_list::const_iterator i
= Paths
.begin(),
3332 const std::string
&s
= *i
;
3333 CmdArgs
.push_back(Args
.MakeArgString(std::string("-L") + s
));
3336 AddLinkerInputs(ToolChain
, Inputs
, Args
, CmdArgs
);
3338 if (D
.CCCIsCXX
&& !Args
.hasArg(options::OPT_nostdlib
)) {
3339 ToolChain
.AddCXXStdlibLibArgs(Args
, CmdArgs
);
3340 CmdArgs
.push_back("-lm");
3343 if (Args
.hasArg(options::OPT_static
))
3344 CmdArgs
.push_back("--start-group");
3346 if (!Args
.hasArg(options::OPT_nostdlib
)) {
3348 CmdArgs
.push_back("-lgcc");
3350 if (Args
.hasArg(options::OPT_static
)) {
3352 CmdArgs
.push_back("-lgcc");
3355 CmdArgs
.push_back("--as-needed");
3356 CmdArgs
.push_back("-lgcc_s");
3358 CmdArgs
.push_back("--no-as-needed");
3361 if (Args
.hasArg(options::OPT_static
))
3362 CmdArgs
.push_back("-lgcc_eh");
3363 else if (!Args
.hasArg(options::OPT_shared
) && D
.CCCIsCXX
)
3364 CmdArgs
.push_back("-lgcc");
3366 if (Args
.hasArg(options::OPT_pthread
) ||
3367 Args
.hasArg(options::OPT_pthreads
))
3368 CmdArgs
.push_back("-lpthread");
3370 CmdArgs
.push_back("-lc");
3372 if (Args
.hasArg(options::OPT_static
))
3373 CmdArgs
.push_back("--end-group");
3376 CmdArgs
.push_back("-lgcc");
3379 CmdArgs
.push_back("--as-needed");
3380 CmdArgs
.push_back("-lgcc_s");
3382 CmdArgs
.push_back("--no-as-needed");
3384 if (!Args
.hasArg(options::OPT_shared
) && D
.CCCIsCXX
)
3385 CmdArgs
.push_back("-lgcc");
3389 if (!Args
.hasArg(options::OPT_nostartfiles
)) {
3391 if (Args
.hasArg(options::OPT_shared
) || Args
.hasArg(options::OPT_pie
))
3392 crtend
= "crtendS.o";
3394 crtend
= "crtend.o";
3396 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath(crtend
)));
3397 CmdArgs
.push_back(Args
.MakeArgString(ToolChain
.GetFilePath("crtn.o")));
3401 if (Args
.hasArg(options::OPT_use_gold_plugin
)) {
3402 CmdArgs
.push_back("-plugin");
3403 std::string Plugin
= ToolChain
.getDriver().Dir
+ "/../lib/LLVMgold.so";
3404 CmdArgs
.push_back(Args
.MakeArgString(Plugin
));
3407 C
.addCommand(new Command(JA
, *this, ToolChain
.Linker
.c_str(), CmdArgs
));
3410 void minix::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3411 const InputInfo
&Output
,
3412 const InputInfoList
&Inputs
,
3413 const ArgList
&Args
,
3414 const char *LinkingOutput
) const {
3415 ArgStringList CmdArgs
;
3417 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3418 options::OPT_Xassembler
);
3420 CmdArgs
.push_back("-o");
3421 CmdArgs
.push_back(Output
.getFilename());
3423 for (InputInfoList::const_iterator
3424 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3425 const InputInfo
&II
= *it
;
3426 CmdArgs
.push_back(II
.getFilename());
3430 Args
.MakeArgString(getToolChain().GetProgramPath("gas"));
3431 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3434 void minix::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3435 const InputInfo
&Output
,
3436 const InputInfoList
&Inputs
,
3437 const ArgList
&Args
,
3438 const char *LinkingOutput
) const {
3439 const Driver
&D
= getToolChain().getDriver();
3440 ArgStringList CmdArgs
;
3442 if (Output
.isFilename()) {
3443 CmdArgs
.push_back("-o");
3444 CmdArgs
.push_back(Output
.getFilename());
3446 assert(Output
.isNothing() && "Invalid output.");
3449 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3450 !Args
.hasArg(options::OPT_nostartfiles
))
3451 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3452 "/usr/gnu/lib/crtso.o")));
3454 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3455 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3456 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3458 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3460 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3461 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3463 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3464 CmdArgs
.push_back("-lm");
3467 if (Args
.hasArg(options::OPT_pthread
))
3468 CmdArgs
.push_back("-lpthread");
3469 CmdArgs
.push_back("-lc");
3470 CmdArgs
.push_back("-lgcc");
3471 CmdArgs
.push_back("-L/usr/gnu/lib");
3472 // FIXME: fill in the correct search path for the final
3473 // support libraries.
3474 CmdArgs
.push_back("-L/usr/gnu/lib/gcc/i686-pc-minix/4.4.3");
3477 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3478 !Args
.hasArg(options::OPT_nostartfiles
)) {
3479 CmdArgs
.push_back(Args
.MakeArgString(getToolChain().GetFilePath(
3480 "/usr/gnu/lib/libend.a")));
3484 Args
.MakeArgString(getToolChain().GetProgramPath("/usr/gnu/bin/gld"));
3485 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3490 // For now, DragonFly Assemble does just about the same as for
3491 // FreeBSD, but this may change soon.
3492 void dragonfly::Assemble::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3493 const InputInfo
&Output
,
3494 const InputInfoList
&Inputs
,
3495 const ArgList
&Args
,
3496 const char *LinkingOutput
) const {
3497 ArgStringList CmdArgs
;
3499 // When building 32-bit code on DragonFly/pc64, we have to explicitly
3500 // instruct as in the base system to assemble 32-bit code.
3501 if (getToolChain().getArchName() == "i386")
3502 CmdArgs
.push_back("--32");
3504 Args
.AddAllArgValues(CmdArgs
, options::OPT_Wa_COMMA
,
3505 options::OPT_Xassembler
);
3507 CmdArgs
.push_back("-o");
3508 CmdArgs
.push_back(Output
.getFilename());
3510 for (InputInfoList::const_iterator
3511 it
= Inputs
.begin(), ie
= Inputs
.end(); it
!= ie
; ++it
) {
3512 const InputInfo
&II
= *it
;
3513 CmdArgs
.push_back(II
.getFilename());
3517 Args
.MakeArgString(getToolChain().GetProgramPath("as"));
3518 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3521 void dragonfly::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3522 const InputInfo
&Output
,
3523 const InputInfoList
&Inputs
,
3524 const ArgList
&Args
,
3525 const char *LinkingOutput
) const {
3526 const Driver
&D
= getToolChain().getDriver();
3527 ArgStringList CmdArgs
;
3529 if (Args
.hasArg(options::OPT_static
)) {
3530 CmdArgs
.push_back("-Bstatic");
3532 if (Args
.hasArg(options::OPT_shared
))
3533 CmdArgs
.push_back("-Bshareable");
3535 CmdArgs
.push_back("-dynamic-linker");
3536 CmdArgs
.push_back("/usr/libexec/ld-elf.so.2");
3540 // When building 32-bit code on DragonFly/pc64, we have to explicitly
3541 // instruct ld in the base system to link 32-bit code.
3542 if (getToolChain().getArchName() == "i386") {
3543 CmdArgs
.push_back("-m");
3544 CmdArgs
.push_back("elf_i386");
3547 if (Output
.isFilename()) {
3548 CmdArgs
.push_back("-o");
3549 CmdArgs
.push_back(Output
.getFilename());
3551 assert(Output
.isNothing() && "Invalid output.");
3554 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3555 !Args
.hasArg(options::OPT_nostartfiles
)) {
3556 if (!Args
.hasArg(options::OPT_shared
)) {
3558 Args
.MakeArgString(getToolChain().GetFilePath("crt1.o")));
3560 Args
.MakeArgString(getToolChain().GetFilePath("crti.o")));
3562 Args
.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
3565 Args
.MakeArgString(getToolChain().GetFilePath("crti.o")));
3567 Args
.MakeArgString(getToolChain().GetFilePath("crtbeginS.o")));
3571 Args
.AddAllArgs(CmdArgs
, options::OPT_L
);
3572 Args
.AddAllArgs(CmdArgs
, options::OPT_T_Group
);
3573 Args
.AddAllArgs(CmdArgs
, options::OPT_e
);
3575 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3577 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3578 !Args
.hasArg(options::OPT_nodefaultlibs
)) {
3579 // FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of
3581 CmdArgs
.push_back("-L/usr/lib/gcc41");
3583 if (!Args
.hasArg(options::OPT_static
)) {
3584 CmdArgs
.push_back("-rpath");
3585 CmdArgs
.push_back("/usr/lib/gcc41");
3587 CmdArgs
.push_back("-rpath-link");
3588 CmdArgs
.push_back("/usr/lib/gcc41");
3590 CmdArgs
.push_back("-rpath");
3591 CmdArgs
.push_back("/usr/lib");
3593 CmdArgs
.push_back("-rpath-link");
3594 CmdArgs
.push_back("/usr/lib");
3598 getToolChain().AddCXXStdlibLibArgs(Args
, CmdArgs
);
3599 CmdArgs
.push_back("-lm");
3602 if (Args
.hasArg(options::OPT_shared
)) {
3603 CmdArgs
.push_back("-lgcc_pic");
3605 CmdArgs
.push_back("-lgcc");
3609 if (Args
.hasArg(options::OPT_pthread
))
3610 CmdArgs
.push_back("-lpthread");
3612 if (!Args
.hasArg(options::OPT_nolibc
)) {
3613 CmdArgs
.push_back("-lc");
3616 if (Args
.hasArg(options::OPT_shared
)) {
3617 CmdArgs
.push_back("-lgcc_pic");
3619 CmdArgs
.push_back("-lgcc");
3623 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3624 !Args
.hasArg(options::OPT_nostartfiles
)) {
3625 if (!Args
.hasArg(options::OPT_shared
))
3626 CmdArgs
.push_back(Args
.MakeArgString(
3627 getToolChain().GetFilePath("crtend.o")));
3629 CmdArgs
.push_back(Args
.MakeArgString(
3630 getToolChain().GetFilePath("crtendS.o")));
3631 CmdArgs
.push_back(Args
.MakeArgString(
3632 getToolChain().GetFilePath("crtn.o")));
3636 Args
.MakeArgString(getToolChain().GetProgramPath("ld"));
3637 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));
3640 void visualstudio::Link::ConstructJob(Compilation
&C
, const JobAction
&JA
,
3641 const InputInfo
&Output
,
3642 const InputInfoList
&Inputs
,
3643 const ArgList
&Args
,
3644 const char *LinkingOutput
) const {
3645 ArgStringList CmdArgs
;
3647 if (Output
.isFilename()) {
3648 CmdArgs
.push_back(Args
.MakeArgString(std::string("-out:") +
3649 Output
.getFilename()));
3651 assert(Output
.isNothing() && "Invalid output.");
3654 if (!Args
.hasArg(options::OPT_nostdlib
) &&
3655 !Args
.hasArg(options::OPT_nostartfiles
)) {
3656 CmdArgs
.push_back("-defaultlib:libcmt");
3659 CmdArgs
.push_back("-nologo");
3661 AddLinkerInputs(getToolChain(), Inputs
, Args
, CmdArgs
);
3664 Args
.MakeArgString(getToolChain().GetProgramPath("link.exe"));
3665 C
.addCommand(new Command(JA
, *this, Exec
, CmdArgs
));