Nick Lewycky | e3365aa | 2010-09-23 23:48:20 +0000 | [diff] [blame] | 1 | //===--- Tools.cpp - Tools Implementations --------------------------------===// |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "Tools.h" |
| 11 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 12 | #include "clang/Driver/Action.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 13 | #include "clang/Driver/Arg.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 14 | #include "clang/Driver/ArgList.h" |
Daniel Dunbar | ee848a7 | 2009-10-29 02:39:57 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Driver.h" |
| 16 | #include "clang/Driver/DriverDiagnostic.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 17 | #include "clang/Driver/Compilation.h" |
| 18 | #include "clang/Driver/Job.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 19 | #include "clang/Driver/HostInfo.h" |
| 20 | #include "clang/Driver/Option.h" |
Daniel Dunbar | 265e9ef | 2009-11-19 04:25:22 +0000 | [diff] [blame] | 21 | #include "clang/Driver/Options.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 22 | #include "clang/Driver/ToolChain.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 23 | #include "clang/Driver/Util.h" |
| 24 | |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallString.h" |
Douglas Gregor | 55d3f7a | 2009-10-29 00:41:01 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringSwitch.h" |
Daniel Dunbar | 5b750fe | 2009-09-09 22:32:34 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/Twine.h" |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 28 | #include "llvm/Support/FileSystem.h" |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Format.h" |
| 30 | #include "llvm/Support/raw_ostream.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Host.h" |
| 32 | #include "llvm/Support/Process.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 33 | |
| 34 | #include "InputInfo.h" |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 35 | #include "ToolChains.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 36 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 37 | using namespace clang::driver; |
| 38 | using namespace clang::driver::tools; |
| 39 | |
Joerg Sonnenberger | 10c6435 | 2011-03-21 14:01:40 +0000 | [diff] [blame] | 40 | /// FindTargetProgramPath - Return path of the target specific version of |
| 41 | /// ProgName. If it doesn't exist, return path of ProgName itself. |
| 42 | static std::string FindTargetProgramPath(const ToolChain &TheToolChain, |
| 43 | const char *ProgName) { |
| 44 | std::string Executable(TheToolChain.getTripleString() + "-" + ProgName); |
| 45 | std::string Path(TheToolChain.GetProgramPath(Executable.c_str())); |
| 46 | if (Path != Executable) |
| 47 | return Path; |
| 48 | return TheToolChain.GetProgramPath(ProgName); |
| 49 | } |
| 50 | |
Daniel Dunbar | 88a3d6c | 2009-09-10 01:21:05 +0000 | [diff] [blame] | 51 | /// CheckPreprocessingOptions - Perform some validation of preprocessing |
| 52 | /// arguments that is shared with gcc. |
| 53 | static void CheckPreprocessingOptions(const Driver &D, const ArgList &Args) { |
| 54 | if (Arg *A = Args.getLastArg(options::OPT_C, options::OPT_CC)) |
Joerg Sonnenberger | 9ade4ae | 2011-03-06 23:31:01 +0000 | [diff] [blame] | 55 | if (!Args.hasArg(options::OPT_E) && !D.CCCIsCPP) |
Daniel Dunbar | 88a3d6c | 2009-09-10 01:21:05 +0000 | [diff] [blame] | 56 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 57 | << A->getAsString(Args) << "-E"; |
| 58 | } |
| 59 | |
Daniel Dunbar | e2fd664 | 2009-09-10 01:21:12 +0000 | [diff] [blame] | 60 | /// CheckCodeGenerationOptions - Perform some validation of code generation |
| 61 | /// arguments that is shared with gcc. |
| 62 | static void CheckCodeGenerationOptions(const Driver &D, const ArgList &Args) { |
| 63 | // In gcc, only ARM checks this, but it seems reasonable to check universally. |
| 64 | if (Args.hasArg(options::OPT_static)) |
| 65 | if (const Arg *A = Args.getLastArg(options::OPT_dynamic, |
| 66 | options::OPT_mdynamic_no_pic)) |
| 67 | D.Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 68 | << A->getAsString(Args) << "-static"; |
| 69 | } |
| 70 | |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 71 | // Quote target names for inclusion in GNU Make dependency files. |
| 72 | // Only the characters '$', '#', ' ', '\t' are quoted. |
| 73 | static void QuoteTarget(llvm::StringRef Target, |
| 74 | llvm::SmallVectorImpl<char> &Res) { |
| 75 | for (unsigned i = 0, e = Target.size(); i != e; ++i) { |
| 76 | switch (Target[i]) { |
| 77 | case ' ': |
| 78 | case '\t': |
| 79 | // Escape the preceding backslashes |
| 80 | for (int j = i - 1; j >= 0 && Target[j] == '\\'; --j) |
| 81 | Res.push_back('\\'); |
| 82 | |
| 83 | // Escape the space/tab |
| 84 | Res.push_back('\\'); |
| 85 | break; |
| 86 | case '$': |
| 87 | Res.push_back('$'); |
| 88 | break; |
| 89 | case '#': |
| 90 | Res.push_back('\\'); |
| 91 | break; |
| 92 | default: |
| 93 | break; |
| 94 | } |
| 95 | |
| 96 | Res.push_back(Target[i]); |
| 97 | } |
| 98 | } |
| 99 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 100 | static void AddLinkerInputs(const ToolChain &TC, |
| 101 | const InputInfoList &Inputs, const ArgList &Args, |
| 102 | ArgStringList &CmdArgs) { |
| 103 | const Driver &D = TC.getDriver(); |
| 104 | |
Daniel Dunbar | 8ac38d7 | 2011-02-19 05:33:51 +0000 | [diff] [blame] | 105 | // Add extra linker input arguments which are not treated as inputs |
| 106 | // (constructed via -Xarch_). |
| 107 | Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input); |
| 108 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 109 | for (InputInfoList::const_iterator |
| 110 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 111 | const InputInfo &II = *it; |
| 112 | |
| 113 | if (!TC.HasNativeLLVMSupport()) { |
| 114 | // Don't try to pass LLVM inputs unless we have native support. |
| 115 | if (II.getType() == types::TY_LLVM_IR || |
| 116 | II.getType() == types::TY_LTO_IR || |
| 117 | II.getType() == types::TY_LLVM_BC || |
| 118 | II.getType() == types::TY_LTO_BC) |
| 119 | D.Diag(clang::diag::err_drv_no_linker_llvm_support) |
| 120 | << TC.getTripleString(); |
| 121 | } |
| 122 | |
Daniel Dunbar | e5a37f4 | 2010-09-17 00:45:02 +0000 | [diff] [blame] | 123 | // Add filenames immediately. |
| 124 | if (II.isFilename()) { |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 125 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | e5a37f4 | 2010-09-17 00:45:02 +0000 | [diff] [blame] | 126 | continue; |
| 127 | } |
| 128 | |
| 129 | // Otherwise, this is a linker input argument. |
| 130 | const Arg &A = II.getInputArg(); |
| 131 | |
| 132 | // Handle reserved library options. |
| 133 | if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 134 | TC.AddCXXStdlibLibArgs(Args, CmdArgs); |
Shantonu Sen | 7433fed | 2010-09-17 18:39:08 +0000 | [diff] [blame] | 135 | } else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext)) { |
| 136 | TC.AddCCKextLibArgs(Args, CmdArgs); |
Daniel Dunbar | e5a37f4 | 2010-09-17 00:45:02 +0000 | [diff] [blame] | 137 | } else |
| 138 | A.renderAsInput(Args, CmdArgs); |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 142 | void Clang::AddPreprocessingOptions(const Driver &D, |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 143 | const ArgList &Args, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 144 | ArgStringList &CmdArgs, |
| 145 | const InputInfo &Output, |
| 146 | const InputInfoList &Inputs) const { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 147 | Arg *A; |
Daniel Dunbar | 3a183d3 | 2009-06-08 21:48:20 +0000 | [diff] [blame] | 148 | |
Daniel Dunbar | 88a3d6c | 2009-09-10 01:21:05 +0000 | [diff] [blame] | 149 | CheckPreprocessingOptions(D, Args); |
| 150 | |
| 151 | Args.AddLastArg(CmdArgs, options::OPT_C); |
| 152 | Args.AddLastArg(CmdArgs, options::OPT_CC); |
Daniel Dunbar | 3a183d3 | 2009-06-08 21:48:20 +0000 | [diff] [blame] | 153 | |
| 154 | // Handle dependency file generation. |
Daniel Dunbar | 9eb93b0 | 2010-12-08 21:33:40 +0000 | [diff] [blame] | 155 | if ((A = Args.getLastArg(options::OPT_M, options::OPT_MM)) || |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 156 | (A = Args.getLastArg(options::OPT_MD)) || |
| 157 | (A = Args.getLastArg(options::OPT_MMD))) { |
| 158 | // Determine the output location. |
| 159 | const char *DepFile; |
| 160 | if (Output.getType() == types::TY_Dependencies) { |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 161 | DepFile = Output.getFilename(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 162 | } else if (Arg *MF = Args.getLastArg(options::OPT_MF)) { |
| 163 | DepFile = MF->getValue(Args); |
Daniel Dunbar | b827a05 | 2009-11-19 03:26:40 +0000 | [diff] [blame] | 164 | } else if (A->getOption().matches(options::OPT_M) || |
| 165 | A->getOption().matches(options::OPT_MM)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 166 | DepFile = "-"; |
| 167 | } else { |
| 168 | DepFile = darwin::CC1::getDependencyFileName(Args, Inputs); |
| 169 | } |
| 170 | CmdArgs.push_back("-dependency-file"); |
| 171 | CmdArgs.push_back(DepFile); |
| 172 | |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 173 | // Add a default target if one wasn't specified. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 174 | if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) { |
| 175 | const char *DepTarget; |
| 176 | |
| 177 | // If user provided -o, that is the dependency target, except |
| 178 | // when we are only generating a dependency file. |
| 179 | Arg *OutputOpt = Args.getLastArg(options::OPT_o); |
| 180 | if (OutputOpt && Output.getType() != types::TY_Dependencies) { |
| 181 | DepTarget = OutputOpt->getValue(Args); |
| 182 | } else { |
| 183 | // Otherwise derive from the base input. |
| 184 | // |
| 185 | // FIXME: This should use the computed output file location. |
Michael J. Spencer | 472ccff | 2010-12-18 00:19:12 +0000 | [diff] [blame] | 186 | llvm::SmallString<128> P(Inputs[0].getBaseInput()); |
| 187 | llvm::sys::path::replace_extension(P, "o"); |
| 188 | DepTarget = Args.MakeArgString(llvm::sys::path::filename(P)); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | CmdArgs.push_back("-MT"); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 192 | llvm::SmallString<128> Quoted; |
| 193 | QuoteTarget(DepTarget, Quoted); |
| 194 | CmdArgs.push_back(Args.MakeArgString(Quoted)); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Daniel Dunbar | b827a05 | 2009-11-19 03:26:40 +0000 | [diff] [blame] | 197 | if (A->getOption().matches(options::OPT_M) || |
| 198 | A->getOption().matches(options::OPT_MD)) |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 199 | CmdArgs.push_back("-sys-header-deps"); |
| 200 | } |
| 201 | |
| 202 | Args.AddLastArg(CmdArgs, options::OPT_MP); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 203 | |
| 204 | // Convert all -MQ <target> args to -MT <quoted target> |
| 205 | for (arg_iterator it = Args.filtered_begin(options::OPT_MT, |
| 206 | options::OPT_MQ), |
| 207 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 208 | const Arg *A = *it; |
| 209 | A->claim(); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 210 | |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 211 | if (A->getOption().matches(options::OPT_MQ)) { |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 212 | CmdArgs.push_back("-MT"); |
| 213 | llvm::SmallString<128> Quoted; |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 214 | QuoteTarget(A->getValue(Args), Quoted); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 215 | CmdArgs.push_back(Args.MakeArgString(Quoted)); |
| 216 | |
| 217 | // -MT flag - no change |
| 218 | } else { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 219 | A->render(Args, CmdArgs); |
Chris Lattner | 3edbeb7 | 2010-03-29 17:55:58 +0000 | [diff] [blame] | 220 | } |
| 221 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 222 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 223 | // Add -i* options, and automatically translate to |
| 224 | // -include-pch/-include-pth for transparent PCH support. It's |
| 225 | // wonky, but we include looking for .gch so we can support seamless |
| 226 | // replacement into a build system already set up to be generating |
| 227 | // .gch files. |
Argyrios Kyrtzidis | 990142a | 2010-09-30 16:53:47 +0000 | [diff] [blame] | 228 | bool RenderedImplicitInclude = false; |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 229 | for (arg_iterator it = Args.filtered_begin(options::OPT_clang_i_Group), |
| 230 | ie = Args.filtered_end(); it != ie; ++it) { |
| 231 | const Arg *A = it; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 232 | |
| 233 | if (A->getOption().matches(options::OPT_include)) { |
Argyrios Kyrtzidis | 990142a | 2010-09-30 16:53:47 +0000 | [diff] [blame] | 234 | bool IsFirstImplicitInclude = !RenderedImplicitInclude; |
| 235 | RenderedImplicitInclude = true; |
| 236 | |
Argyrios Kyrtzidis | e5c3537 | 2010-08-11 23:27:58 +0000 | [diff] [blame] | 237 | // Use PCH if the user requested it. |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 238 | bool UsePCH = D.CCCUsePCH; |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 239 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 240 | bool FoundPTH = false; |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 241 | bool FoundPCH = false; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 242 | llvm::sys::Path P(A->getValue(Args)); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 243 | bool Exists; |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 244 | if (UsePCH) { |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 245 | P.appendSuffix("pch"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 246 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 247 | FoundPCH = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 248 | else |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 249 | P.eraseSuffix(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 252 | if (!FoundPCH) { |
| 253 | P.appendSuffix("pth"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 254 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 255 | FoundPTH = true; |
| 256 | else |
| 257 | P.eraseSuffix(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 260 | if (!FoundPCH && !FoundPTH) { |
| 261 | P.appendSuffix("gch"); |
Michael J. Spencer | 32bef4e | 2011-01-10 02:34:13 +0000 | [diff] [blame] | 262 | if (!llvm::sys::fs::exists(P.str(), Exists) && Exists) { |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 263 | FoundPCH = UsePCH; |
| 264 | FoundPTH = !UsePCH; |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 265 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 266 | else |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 267 | P.eraseSuffix(); |
| 268 | } |
| 269 | |
| 270 | if (FoundPCH || FoundPTH) { |
Argyrios Kyrtzidis | 990142a | 2010-09-30 16:53:47 +0000 | [diff] [blame] | 271 | if (IsFirstImplicitInclude) { |
| 272 | A->claim(); |
| 273 | if (UsePCH) |
| 274 | CmdArgs.push_back("-include-pch"); |
| 275 | else |
| 276 | CmdArgs.push_back("-include-pth"); |
| 277 | CmdArgs.push_back(Args.MakeArgString(P.str())); |
| 278 | continue; |
| 279 | } else { |
| 280 | // Ignore the PCH if not first on command line and emit warning. |
| 281 | D.Diag(clang::diag::warn_drv_pch_not_first_include) |
| 282 | << P.str() << A->getAsString(Args); |
| 283 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
| 287 | // Not translated, render as usual. |
| 288 | A->claim(); |
| 289 | A->render(Args, CmdArgs); |
| 290 | } |
| 291 | |
| 292 | Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U); |
| 293 | Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F); |
| 294 | |
Daniel Dunbar | 641b98b | 2010-09-14 23:12:35 +0000 | [diff] [blame] | 295 | // Add C++ include arguments, if needed. |
| 296 | types::ID InputType = Inputs[0].getType(); |
| 297 | if (types::isCXX(InputType)) |
| 298 | getToolChain().AddClangCXXStdlibIncludeArgs(Args, CmdArgs); |
| 299 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 300 | // Add -Wp, and -Xassembler if using the preprocessor. |
| 301 | |
| 302 | // FIXME: There is a very unfortunate problem here, some troubled |
| 303 | // souls abuse -Wp, to pass preprocessor options in gcc syntax. To |
| 304 | // really support that we would have to parse and then translate |
| 305 | // those options. :( |
| 306 | Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA, |
| 307 | options::OPT_Xpreprocessor); |
Daniel Dunbar | 607d7f6 | 2009-10-29 01:53:44 +0000 | [diff] [blame] | 308 | |
| 309 | // -I- is a deprecated GCC feature, reject it. |
| 310 | if (Arg *A = Args.getLastArg(options::OPT_I_)) |
| 311 | D.Diag(clang::diag::err_drv_I_dash_not_supported) << A->getAsString(Args); |
Chandler Carruth | feee58c | 2010-10-20 07:00:47 +0000 | [diff] [blame] | 312 | |
| 313 | // If we have a --sysroot, and don't have an explicit -isysroot flag, add an |
| 314 | // -isysroot to the CC1 invocation. |
| 315 | if (Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) { |
| 316 | if (!Args.hasArg(options::OPT_isysroot)) { |
| 317 | CmdArgs.push_back("-isysroot"); |
| 318 | CmdArgs.push_back(A->getValue(Args)); |
| 319 | } |
| 320 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 323 | /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targetting. |
| 324 | // |
| 325 | // FIXME: tblgen this. |
Rafael Espindola | bcd6df6 | 2010-06-28 17:18:09 +0000 | [diff] [blame] | 326 | static const char *getARMTargetCPU(const ArgList &Args, |
| 327 | const llvm::Triple &Triple) { |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 328 | // FIXME: Warn on inconsistent use of -mcpu and -march. |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 329 | |
| 330 | // If we have -mcpu=, use that. |
| 331 | if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) |
| 332 | return A->getValue(Args); |
| 333 | |
Rafael Espindola | bcd6df6 | 2010-06-28 17:18:09 +0000 | [diff] [blame] | 334 | llvm::StringRef MArch; |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 335 | if (Arg *A = Args.getLastArg(options::OPT_march_EQ)) { |
Rafael Espindola | bcd6df6 | 2010-06-28 17:18:09 +0000 | [diff] [blame] | 336 | // Otherwise, if we have -march= choose the base CPU for that arch. |
| 337 | MArch = A->getValue(Args); |
| 338 | } else { |
| 339 | // Otherwise, use the Arch from the triple. |
| 340 | MArch = Triple.getArchName(); |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Rafael Espindola | bcd6df6 | 2010-06-28 17:18:09 +0000 | [diff] [blame] | 343 | if (MArch == "armv2" || MArch == "armv2a") |
| 344 | return "arm2"; |
| 345 | if (MArch == "armv3") |
| 346 | return "arm6"; |
| 347 | if (MArch == "armv3m") |
| 348 | return "arm7m"; |
| 349 | if (MArch == "armv4" || MArch == "armv4t") |
| 350 | return "arm7tdmi"; |
| 351 | if (MArch == "armv5" || MArch == "armv5t") |
| 352 | return "arm10tdmi"; |
| 353 | if (MArch == "armv5e" || MArch == "armv5te") |
| 354 | return "arm1026ejs"; |
| 355 | if (MArch == "armv5tej") |
| 356 | return "arm926ej-s"; |
| 357 | if (MArch == "armv6" || MArch == "armv6k") |
| 358 | return "arm1136jf-s"; |
| 359 | if (MArch == "armv6j") |
| 360 | return "arm1136j-s"; |
| 361 | if (MArch == "armv6z" || MArch == "armv6zk") |
| 362 | return "arm1176jzf-s"; |
| 363 | if (MArch == "armv6t2") |
| 364 | return "arm1156t2-s"; |
| 365 | if (MArch == "armv7" || MArch == "armv7a" || MArch == "armv7-a") |
| 366 | return "cortex-a8"; |
| 367 | if (MArch == "armv7r" || MArch == "armv7-r") |
| 368 | return "cortex-r4"; |
| 369 | if (MArch == "armv7m" || MArch == "armv7-m") |
| 370 | return "cortex-m3"; |
| 371 | if (MArch == "ep9312") |
| 372 | return "ep9312"; |
| 373 | if (MArch == "iwmmxt") |
| 374 | return "iwmmxt"; |
| 375 | if (MArch == "xscale") |
| 376 | return "xscale"; |
Bob Wilson | 1ec0ade | 2011-03-21 20:40:05 +0000 | [diff] [blame] | 377 | if (MArch == "armv6m" || MArch == "armv6-m") |
| 378 | return "cortex-m0"; |
Rafael Espindola | bcd6df6 | 2010-06-28 17:18:09 +0000 | [diff] [blame] | 379 | |
| 380 | // If all else failed, return the most base CPU LLVM supports. |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 381 | return "arm7tdmi"; |
| 382 | } |
| 383 | |
Daniel Dunbar | 1d65e4b | 2009-09-10 22:59:51 +0000 | [diff] [blame] | 384 | /// getLLVMArchSuffixForARM - Get the LLVM arch name to use for a particular |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 385 | /// CPU. |
| 386 | // |
| 387 | // FIXME: This is redundant with -mcpu, why does LLVM use this. |
| 388 | // FIXME: tblgen this, or kill it! |
Daniel Dunbar | 1d65e4b | 2009-09-10 22:59:51 +0000 | [diff] [blame] | 389 | static const char *getLLVMArchSuffixForARM(llvm::StringRef CPU) { |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 390 | if (CPU == "arm7tdmi" || CPU == "arm7tdmi-s" || CPU == "arm710t" || |
| 391 | CPU == "arm720t" || CPU == "arm9" || CPU == "arm9tdmi" || |
| 392 | CPU == "arm920" || CPU == "arm920t" || CPU == "arm922t" || |
| 393 | CPU == "arm940t" || CPU == "ep9312") |
Daniel Dunbar | 1d65e4b | 2009-09-10 22:59:51 +0000 | [diff] [blame] | 394 | return "v4t"; |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 395 | |
| 396 | if (CPU == "arm10tdmi" || CPU == "arm1020t") |
Daniel Dunbar | 1d65e4b | 2009-09-10 22:59:51 +0000 | [diff] [blame] | 397 | return "v5"; |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 398 | |
| 399 | if (CPU == "arm9e" || CPU == "arm926ej-s" || CPU == "arm946e-s" || |
| 400 | CPU == "arm966e-s" || CPU == "arm968e-s" || CPU == "arm10e" || |
| 401 | CPU == "arm1020e" || CPU == "arm1022e" || CPU == "xscale" || |
| 402 | CPU == "iwmmxt") |
Daniel Dunbar | 1d65e4b | 2009-09-10 22:59:51 +0000 | [diff] [blame] | 403 | return "v5e"; |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 404 | |
| 405 | if (CPU == "arm1136j-s" || CPU == "arm1136jf-s" || CPU == "arm1176jz-s" || |
| 406 | CPU == "arm1176jzf-s" || CPU == "mpcorenovfp" || CPU == "mpcore") |
Daniel Dunbar | 1d65e4b | 2009-09-10 22:59:51 +0000 | [diff] [blame] | 407 | return "v6"; |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 408 | |
| 409 | if (CPU == "arm1156t2-s" || CPU == "arm1156t2f-s") |
Daniel Dunbar | 1d65e4b | 2009-09-10 22:59:51 +0000 | [diff] [blame] | 410 | return "v6t2"; |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 411 | |
| 412 | if (CPU == "cortex-a8" || CPU == "cortex-a9") |
Daniel Dunbar | 1d65e4b | 2009-09-10 22:59:51 +0000 | [diff] [blame] | 413 | return "v7"; |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 414 | |
Daniel Dunbar | 1d65e4b | 2009-09-10 22:59:51 +0000 | [diff] [blame] | 415 | return ""; |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Daniel Dunbar | 1f95e65 | 2009-11-17 06:37:03 +0000 | [diff] [blame] | 418 | // FIXME: Move to target hook. |
| 419 | static bool isSignedCharDefault(const llvm::Triple &Triple) { |
| 420 | switch (Triple.getArch()) { |
| 421 | default: |
| 422 | return true; |
| 423 | |
| 424 | case llvm::Triple::ppc: |
| 425 | case llvm::Triple::ppc64: |
| 426 | if (Triple.getOS() == llvm::Triple::Darwin) |
| 427 | return true; |
| 428 | return false; |
| 429 | |
| 430 | case llvm::Triple::systemz: |
| 431 | return false; |
| 432 | } |
| 433 | } |
| 434 | |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 435 | void Clang::AddARMTargetArgs(const ArgList &Args, |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 436 | ArgStringList &CmdArgs, |
| 437 | bool KernelOrKext) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 438 | const Driver &D = getToolChain().getDriver(); |
Rafael Espindola | bcd6df6 | 2010-06-28 17:18:09 +0000 | [diff] [blame] | 439 | llvm::Triple Triple = getToolChain().getTriple(); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 440 | |
Daniel Dunbar | db04e2e | 2011-03-02 00:55:57 +0000 | [diff] [blame] | 441 | // Disable movt generation, if requested. |
| 442 | #ifdef DISABLE_ARM_DARWIN_USE_MOVT |
Daniel Dunbar | 3c66d30 | 2011-03-22 16:48:17 +0000 | [diff] [blame] | 443 | CmdArgs.push_back("-backend-option"); |
Daniel Dunbar | db04e2e | 2011-03-02 00:55:57 +0000 | [diff] [blame] | 444 | CmdArgs.push_back("-arm-darwin-use-movt=0"); |
| 445 | #endif |
| 446 | |
Daniel Dunbar | 2030d8f | 2009-09-14 00:34:46 +0000 | [diff] [blame] | 447 | // Select the ABI to use. |
| 448 | // |
| 449 | // FIXME: Support -meabi. |
| 450 | const char *ABIName = 0; |
| 451 | if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) { |
| 452 | ABIName = A->getValue(Args); |
| 453 | } else { |
| 454 | // Select the default based on the platform. |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 455 | switch(Triple.getEnvironment()) { |
| 456 | case llvm::Triple::GNUEABI: |
Daniel Dunbar | 2030d8f | 2009-09-14 00:34:46 +0000 | [diff] [blame] | 457 | ABIName = "aapcs-linux"; |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 458 | break; |
| 459 | case llvm::Triple::EABI: |
Rafael Espindola | 1ed1a59 | 2010-06-16 19:01:17 +0000 | [diff] [blame] | 460 | ABIName = "aapcs"; |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 461 | break; |
| 462 | default: |
Rafael Espindola | 1ed1a59 | 2010-06-16 19:01:17 +0000 | [diff] [blame] | 463 | ABIName = "apcs-gnu"; |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 464 | } |
Daniel Dunbar | 2030d8f | 2009-09-14 00:34:46 +0000 | [diff] [blame] | 465 | } |
| 466 | CmdArgs.push_back("-target-abi"); |
| 467 | CmdArgs.push_back(ABIName); |
| 468 | |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 469 | // Set the CPU based on -march= and -mcpu=. |
Daniel Dunbar | 38b48af | 2009-12-18 06:30:12 +0000 | [diff] [blame] | 470 | CmdArgs.push_back("-target-cpu"); |
Rafael Espindola | bcd6df6 | 2010-06-28 17:18:09 +0000 | [diff] [blame] | 471 | CmdArgs.push_back(getARMTargetCPU(Args, Triple)); |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 472 | |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 473 | // Select the float ABI as determined by -msoft-float, -mhard-float, and |
| 474 | // -mfloat-abi=. |
| 475 | llvm::StringRef FloatABI; |
| 476 | if (Arg *A = Args.getLastArg(options::OPT_msoft_float, |
| 477 | options::OPT_mhard_float, |
| 478 | options::OPT_mfloat_abi_EQ)) { |
| 479 | if (A->getOption().matches(options::OPT_msoft_float)) |
| 480 | FloatABI = "soft"; |
| 481 | else if (A->getOption().matches(options::OPT_mhard_float)) |
| 482 | FloatABI = "hard"; |
| 483 | else { |
| 484 | FloatABI = A->getValue(Args); |
| 485 | if (FloatABI != "soft" && FloatABI != "softfp" && FloatABI != "hard") { |
| 486 | D.Diag(clang::diag::err_drv_invalid_mfloat_abi) |
| 487 | << A->getAsString(Args); |
| 488 | FloatABI = "soft"; |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | // If unspecified, choose the default based on the platform. |
| 494 | if (FloatABI.empty()) { |
Rafael Espindola | bcd6df6 | 2010-06-28 17:18:09 +0000 | [diff] [blame] | 495 | const llvm::Triple &Triple = getToolChain().getTriple(); |
| 496 | switch (Triple.getOS()) { |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 497 | case llvm::Triple::Darwin: { |
| 498 | // Darwin defaults to "softfp" for v6 and v7. |
| 499 | // |
| 500 | // FIXME: Factor out an ARM class so we can cache the arch somewhere. |
Rafael Espindola | bcd6df6 | 2010-06-28 17:18:09 +0000 | [diff] [blame] | 501 | llvm::StringRef ArchName = |
| 502 | getLLVMArchSuffixForARM(getARMTargetCPU(Args, Triple)); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 503 | if (ArchName.startswith("v6") || ArchName.startswith("v7")) |
| 504 | FloatABI = "softfp"; |
| 505 | else |
| 506 | FloatABI = "soft"; |
| 507 | break; |
| 508 | } |
| 509 | |
Rafael Espindola | 7e9cebf | 2010-06-27 18:29:21 +0000 | [diff] [blame] | 510 | case llvm::Triple::Linux: { |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 511 | if (getToolChain().getTriple().getEnvironment() == llvm::Triple::GNUEABI) { |
Rafael Espindola | 7e9cebf | 2010-06-27 18:29:21 +0000 | [diff] [blame] | 512 | FloatABI = "softfp"; |
| 513 | break; |
| 514 | } |
| 515 | } |
| 516 | // fall through |
| 517 | |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 518 | default: |
Bob Wilson | fc2bd7c | 2011-02-04 17:59:28 +0000 | [diff] [blame] | 519 | switch(Triple.getEnvironment()) { |
| 520 | case llvm::Triple::GNUEABI: |
| 521 | FloatABI = "softfp"; |
| 522 | break; |
| 523 | case llvm::Triple::EABI: |
| 524 | // EABI is always AAPCS, and if it was not marked 'hard', it's softfp |
| 525 | FloatABI = "softfp"; |
| 526 | break; |
| 527 | default: |
| 528 | // Assume "soft", but warn the user we are guessing. |
| 529 | FloatABI = "soft"; |
| 530 | D.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is) << "soft"; |
| 531 | break; |
| 532 | } |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
| 536 | if (FloatABI == "soft") { |
| 537 | // Floating point operations and argument passing are soft. |
| 538 | // |
| 539 | // FIXME: This changes CPP defines, we need -target-soft-float. |
Daniel Dunbar | 3b31526 | 2009-11-30 08:42:00 +0000 | [diff] [blame] | 540 | CmdArgs.push_back("-msoft-float"); |
Daniel Dunbar | 87667aa | 2009-12-08 19:49:51 +0000 | [diff] [blame] | 541 | CmdArgs.push_back("-mfloat-abi"); |
| 542 | CmdArgs.push_back("soft"); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 543 | } else if (FloatABI == "softfp") { |
| 544 | // Floating point operations are hard, but argument passing is soft. |
Daniel Dunbar | 87667aa | 2009-12-08 19:49:51 +0000 | [diff] [blame] | 545 | CmdArgs.push_back("-mfloat-abi"); |
| 546 | CmdArgs.push_back("soft"); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 547 | } else { |
| 548 | // Floating point operations and argument passing are hard. |
| 549 | assert(FloatABI == "hard" && "Invalid float abi!"); |
Daniel Dunbar | 87667aa | 2009-12-08 19:49:51 +0000 | [diff] [blame] | 550 | CmdArgs.push_back("-mfloat-abi"); |
| 551 | CmdArgs.push_back("hard"); |
Daniel Dunbar | cbd1933 | 2009-09-10 23:00:09 +0000 | [diff] [blame] | 552 | } |
Daniel Dunbar | 97f52ac | 2009-12-19 04:15:38 +0000 | [diff] [blame] | 553 | |
| 554 | // Set appropriate target features for floating point mode. |
| 555 | // |
| 556 | // FIXME: Note, this is a hack, the LLVM backend doesn't actually use these |
| 557 | // yet (it uses the -mfloat-abi and -msoft-float options above), and it is |
| 558 | // stripped out by the ARM target. |
| 559 | |
| 560 | // Use software floating point operations? |
| 561 | if (FloatABI == "soft") { |
| 562 | CmdArgs.push_back("-target-feature"); |
| 563 | CmdArgs.push_back("+soft-float"); |
| 564 | } |
| 565 | |
| 566 | // Use software floating point argument passing? |
| 567 | if (FloatABI != "hard") { |
| 568 | CmdArgs.push_back("-target-feature"); |
| 569 | CmdArgs.push_back("+soft-float-abi"); |
| 570 | } |
Daniel Dunbar | a91320b | 2009-12-21 23:28:17 +0000 | [diff] [blame] | 571 | |
| 572 | // Honor -mfpu=. |
| 573 | // |
| 574 | // FIXME: Centralize feature selection, defaulting shouldn't be also in the |
| 575 | // frontend target. |
| 576 | if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) { |
| 577 | llvm::StringRef FPU = A->getValue(Args); |
| 578 | |
| 579 | // Set the target features based on the FPU. |
| 580 | if (FPU == "fpa" || FPU == "fpe2" || FPU == "fpe3" || FPU == "maverick") { |
| 581 | // Disable any default FPU support. |
| 582 | CmdArgs.push_back("-target-feature"); |
| 583 | CmdArgs.push_back("-vfp2"); |
| 584 | CmdArgs.push_back("-target-feature"); |
| 585 | CmdArgs.push_back("-vfp3"); |
| 586 | CmdArgs.push_back("-target-feature"); |
| 587 | CmdArgs.push_back("-neon"); |
| 588 | } else if (FPU == "vfp") { |
| 589 | CmdArgs.push_back("-target-feature"); |
| 590 | CmdArgs.push_back("+vfp2"); |
| 591 | } else if (FPU == "vfp3") { |
| 592 | CmdArgs.push_back("-target-feature"); |
| 593 | CmdArgs.push_back("+vfp3"); |
| 594 | } else if (FPU == "neon") { |
| 595 | CmdArgs.push_back("-target-feature"); |
| 596 | CmdArgs.push_back("+neon"); |
| 597 | } else |
| 598 | D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args); |
| 599 | } |
Daniel Dunbar | 7187fac | 2011-03-17 00:07:34 +0000 | [diff] [blame] | 600 | |
| 601 | // Setting -msoft-float effectively disables NEON because of the GCC |
| 602 | // implementation, although the same isn't true of VFP or VFP3. |
| 603 | if (FloatABI == "soft") { |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 604 | CmdArgs.push_back("-target-feature"); |
| 605 | CmdArgs.push_back("-neon"); |
| 606 | } |
| 607 | |
| 608 | // Kernel code has more strict alignment requirements. |
| 609 | if (KernelOrKext) { |
Daniel Dunbar | 3c66d30 | 2011-03-22 16:48:17 +0000 | [diff] [blame] | 610 | CmdArgs.push_back("-backend-option"); |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 611 | CmdArgs.push_back("-arm-long-calls"); |
| 612 | |
Daniel Dunbar | 3c66d30 | 2011-03-22 16:48:17 +0000 | [diff] [blame] | 613 | CmdArgs.push_back("-backend-option"); |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 614 | CmdArgs.push_back("-arm-strict-align"); |
Daniel Dunbar | 7187fac | 2011-03-17 00:07:34 +0000 | [diff] [blame] | 615 | } |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 618 | void Clang::AddMIPSTargetArgs(const ArgList &Args, |
| 619 | ArgStringList &CmdArgs) const { |
| 620 | const Driver &D = getToolChain().getDriver(); |
| 621 | |
| 622 | // Select the ABI to use. |
| 623 | const char *ABIName = 0; |
| 624 | if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) { |
| 625 | ABIName = A->getValue(Args); |
| 626 | } else { |
| 627 | ABIName = "o32"; |
| 628 | } |
| 629 | |
| 630 | CmdArgs.push_back("-target-abi"); |
| 631 | CmdArgs.push_back(ABIName); |
| 632 | |
| 633 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { |
| 634 | llvm::StringRef MArch = A->getValue(Args); |
| 635 | CmdArgs.push_back("-target-cpu"); |
| 636 | |
| 637 | if ((MArch == "r2000") || (MArch == "r3000")) |
| 638 | CmdArgs.push_back("mips1"); |
| 639 | else if (MArch == "r6000") |
| 640 | CmdArgs.push_back("mips2"); |
| 641 | else |
| 642 | CmdArgs.push_back(MArch.str().c_str()); |
| 643 | } |
| 644 | |
| 645 | // Select the float ABI as determined by -msoft-float, -mhard-float, and |
| 646 | llvm::StringRef FloatABI; |
| 647 | if (Arg *A = Args.getLastArg(options::OPT_msoft_float, |
| 648 | options::OPT_mhard_float)) { |
| 649 | if (A->getOption().matches(options::OPT_msoft_float)) |
| 650 | FloatABI = "soft"; |
| 651 | else if (A->getOption().matches(options::OPT_mhard_float)) |
| 652 | FloatABI = "hard"; |
| 653 | } |
| 654 | |
| 655 | // If unspecified, choose the default based on the platform. |
| 656 | if (FloatABI.empty()) { |
Benjamin Kramer | 71c972a | 2010-04-08 15:44:22 +0000 | [diff] [blame] | 657 | // Assume "soft", but warn the user we are guessing. |
| 658 | FloatABI = "soft"; |
| 659 | D.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is) << "soft"; |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | if (FloatABI == "soft") { |
| 663 | // Floating point operations and argument passing are soft. |
| 664 | // |
| 665 | // FIXME: This changes CPP defines, we need -target-soft-float. |
| 666 | CmdArgs.push_back("-msoft-float"); |
| 667 | } else { |
| 668 | assert(FloatABI == "hard" && "Invalid float abi!"); |
| 669 | CmdArgs.push_back("-mhard-float"); |
| 670 | } |
| 671 | } |
| 672 | |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 673 | void Clang::AddSparcTargetArgs(const ArgList &Args, |
| 674 | ArgStringList &CmdArgs) const { |
| 675 | const Driver &D = getToolChain().getDriver(); |
| 676 | |
| 677 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { |
| 678 | llvm::StringRef MArch = A->getValue(Args); |
| 679 | CmdArgs.push_back("-target-cpu"); |
| 680 | CmdArgs.push_back(MArch.str().c_str()); |
| 681 | } |
| 682 | |
| 683 | // Select the float ABI as determined by -msoft-float, -mhard-float, and |
| 684 | llvm::StringRef FloatABI; |
| 685 | if (Arg *A = Args.getLastArg(options::OPT_msoft_float, |
| 686 | options::OPT_mhard_float)) { |
| 687 | if (A->getOption().matches(options::OPT_msoft_float)) |
| 688 | FloatABI = "soft"; |
| 689 | else if (A->getOption().matches(options::OPT_mhard_float)) |
| 690 | FloatABI = "hard"; |
| 691 | } |
| 692 | |
| 693 | // If unspecified, choose the default based on the platform. |
| 694 | if (FloatABI.empty()) { |
| 695 | switch (getToolChain().getTriple().getOS()) { |
| 696 | default: |
| 697 | // Assume "soft", but warn the user we are guessing. |
| 698 | FloatABI = "soft"; |
| 699 | D.Diag(clang::diag::warn_drv_assuming_mfloat_abi_is) << "soft"; |
| 700 | break; |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | if (FloatABI == "soft") { |
| 705 | // Floating point operations and argument passing are soft. |
| 706 | // |
| 707 | // FIXME: This changes CPP defines, we need -target-soft-float. |
| 708 | CmdArgs.push_back("-msoft-float"); |
| 709 | CmdArgs.push_back("soft"); |
| 710 | CmdArgs.push_back("-target-feature"); |
| 711 | CmdArgs.push_back("+soft-float"); |
| 712 | } else { |
| 713 | assert(FloatABI == "hard" && "Invalid float abi!"); |
| 714 | CmdArgs.push_back("-mhard-float"); |
| 715 | } |
| 716 | } |
| 717 | |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 718 | void Clang::AddX86TargetArgs(const ArgList &Args, |
| 719 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | e6ad3f9 | 2009-09-10 22:59:57 +0000 | [diff] [blame] | 720 | if (!Args.hasFlag(options::OPT_mred_zone, |
| 721 | options::OPT_mno_red_zone, |
| 722 | true) || |
| 723 | Args.hasArg(options::OPT_mkernel) || |
| 724 | Args.hasArg(options::OPT_fapple_kext)) |
Daniel Dunbar | 66861e0 | 2009-11-20 22:21:36 +0000 | [diff] [blame] | 725 | CmdArgs.push_back("-disable-red-zone"); |
Daniel Dunbar | e6ad3f9 | 2009-09-10 22:59:57 +0000 | [diff] [blame] | 726 | |
Daniel Dunbar | e6ad3f9 | 2009-09-10 22:59:57 +0000 | [diff] [blame] | 727 | if (Args.hasFlag(options::OPT_msoft_float, |
| 728 | options::OPT_mno_soft_float, |
| 729 | false)) |
Daniel Dunbar | 66861e0 | 2009-11-20 22:21:36 +0000 | [diff] [blame] | 730 | CmdArgs.push_back("-no-implicit-float"); |
Daniel Dunbar | e6ad3f9 | 2009-09-10 22:59:57 +0000 | [diff] [blame] | 731 | |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 732 | const char *CPUName = 0; |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 733 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 734 | if (llvm::StringRef(A->getValue(Args)) == "native") { |
| 735 | // FIXME: Reject attempts to use -march=native unless the target matches |
| 736 | // the host. |
| 737 | // |
| 738 | // FIXME: We should also incorporate the detected target features for use |
| 739 | // with -native. |
| 740 | std::string CPU = llvm::sys::getHostCPUName(); |
| 741 | if (!CPU.empty()) |
| 742 | CPUName = Args.MakeArgString(CPU); |
| 743 | } else |
| 744 | CPUName = A->getValue(Args); |
| 745 | } |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 746 | |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 747 | // Select the default CPU if none was given (or detection failed). |
| 748 | if (!CPUName) { |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 749 | // FIXME: Need target hooks. |
Benjamin Kramer | f22d1fd | 2010-01-30 15:01:47 +0000 | [diff] [blame] | 750 | if (getToolChain().getOS().startswith("darwin")) { |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 751 | if (getToolChain().getArchName() == "x86_64") |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 752 | CPUName = "core2"; |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 753 | else if (getToolChain().getArchName() == "i386") |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 754 | CPUName = "yonah"; |
Chris Lattner | 86ed3a3 | 2010-04-11 19:29:39 +0000 | [diff] [blame] | 755 | } else if (getToolChain().getOS().startswith("haiku")) { |
| 756 | if (getToolChain().getArchName() == "x86_64") |
| 757 | CPUName = "x86-64"; |
| 758 | else if (getToolChain().getArchName() == "i386") |
| 759 | CPUName = "i586"; |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 760 | } else if (getToolChain().getOS().startswith("openbsd")) { |
| 761 | if (getToolChain().getArchName() == "x86_64") |
| 762 | CPUName = "x86-64"; |
| 763 | else if (getToolChain().getArchName() == "i386") |
| 764 | CPUName = "i486"; |
Roman Divacky | 451f8ca | 2011-03-01 18:11:37 +0000 | [diff] [blame] | 765 | } else if (getToolChain().getOS().startswith("freebsd")) { |
| 766 | if (getToolChain().getArchName() == "x86_64") |
| 767 | CPUName = "x86-64"; |
| 768 | else if (getToolChain().getArchName() == "i386") |
| 769 | CPUName = "i486"; |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 770 | } else if (getToolChain().getOS().startswith("netbsd")) { |
| 771 | if (getToolChain().getArchName() == "x86_64") |
| 772 | CPUName = "x86-64"; |
| 773 | else if (getToolChain().getArchName() == "i386") |
| 774 | CPUName = "i486"; |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 775 | } else { |
| 776 | if (getToolChain().getArchName() == "x86_64") |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 777 | CPUName = "x86-64"; |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 778 | else if (getToolChain().getArchName() == "i386") |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 779 | CPUName = "pentium4"; |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 783 | if (CPUName) { |
Daniel Dunbar | 38b48af | 2009-12-18 06:30:12 +0000 | [diff] [blame] | 784 | CmdArgs.push_back("-target-cpu"); |
Daniel Dunbar | f86fedd | 2009-11-14 22:04:54 +0000 | [diff] [blame] | 785 | CmdArgs.push_back(CPUName); |
| 786 | } |
| 787 | |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 788 | for (arg_iterator it = Args.filtered_begin(options::OPT_m_x86_Features_Group), |
| 789 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 790 | llvm::StringRef Name = (*it)->getOption().getName(); |
| 791 | (*it)->claim(); |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 792 | |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 793 | // Skip over "-m". |
| 794 | assert(Name.startswith("-m") && "Invalid feature name."); |
| 795 | Name = Name.substr(2); |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 796 | |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 797 | bool IsNegative = Name.startswith("no-"); |
| 798 | if (IsNegative) |
| 799 | Name = Name.substr(3); |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 800 | |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 801 | CmdArgs.push_back("-target-feature"); |
| 802 | CmdArgs.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name)); |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | |
Anders Carlsson | 525544d | 2011-02-28 00:44:51 +0000 | [diff] [blame] | 806 | static bool |
| 807 | shouldUseExceptionTablesForObjCExceptions(const ArgList &Args, |
| 808 | const llvm::Triple &Triple) { |
| 809 | // We use the zero-cost exception tables for Objective-C if the non-fragile |
| 810 | // ABI is enabled or when compiling for x86_64 and ARM on Snow Leopard and |
| 811 | // later. |
| 812 | |
| 813 | if (Args.hasArg(options::OPT_fobjc_nonfragile_abi)) |
| 814 | return true; |
| 815 | |
| 816 | if (Triple.getOS() != llvm::Triple::Darwin) |
| 817 | return false; |
| 818 | |
| 819 | return (Triple.getDarwinMajorNumber() >= 9 && |
| 820 | (Triple.getArch() == llvm::Triple::x86_64 || |
| 821 | Triple.getArch() == llvm::Triple::arm)); |
| 822 | } |
| 823 | |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 824 | /// addExceptionArgs - Adds exception related arguments to the driver command |
| 825 | /// arguments. There's a master flag, -fexceptions and also language specific |
| 826 | /// flags to enable/disable C++ and Objective-C exceptions. |
| 827 | /// This makes it possible to for example disable C++ exceptions but enable |
| 828 | /// Objective-C exceptions. |
| 829 | static void addExceptionArgs(const ArgList &Args, types::ID InputType, |
| 830 | const llvm::Triple &Triple, |
| 831 | bool KernelOrKext, bool IsRewriter, |
| 832 | ArgStringList &CmdArgs) { |
| 833 | if (KernelOrKext) |
| 834 | return; |
| 835 | |
| 836 | // Exceptions are enabled by default. |
| 837 | bool ExceptionsEnabled = true; |
| 838 | |
| 839 | // This keeps track of whether exceptions were explicitly turned on or off. |
| 840 | bool DidHaveExplicitExceptionFlag = false; |
| 841 | |
Rafael Espindola | f759df0 | 2009-10-01 13:33:33 +0000 | [diff] [blame] | 842 | if (Arg *A = Args.getLastArg(options::OPT_fexceptions, |
| 843 | options::OPT_fno_exceptions)) { |
| 844 | if (A->getOption().matches(options::OPT_fexceptions)) |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 845 | ExceptionsEnabled = true; |
| 846 | else |
| 847 | ExceptionsEnabled = false; |
| 848 | |
| 849 | DidHaveExplicitExceptionFlag = true; |
Rafael Espindola | f759df0 | 2009-10-01 13:33:33 +0000 | [diff] [blame] | 850 | } |
Daniel Dunbar | 1a2cd4f | 2010-09-14 23:12:31 +0000 | [diff] [blame] | 851 | |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 852 | bool ShouldUseExceptionTables = false; |
Fariborz Jahanian | 85caf03 | 2009-10-01 20:30:46 +0000 | [diff] [blame] | 853 | |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 854 | // Exception tables and cleanups can be enabled with -fexceptions even if the |
| 855 | // language itself doesn't support exceptions. |
| 856 | if (ExceptionsEnabled && DidHaveExplicitExceptionFlag) |
| 857 | ShouldUseExceptionTables = true; |
Daniel Dunbar | 1a2cd4f | 2010-09-14 23:12:31 +0000 | [diff] [blame] | 858 | |
Daniel Dunbar | d47ea69 | 2011-03-17 23:28:31 +0000 | [diff] [blame] | 859 | // Obj-C exceptions are enabled by default, regardless of -fexceptions. This |
| 860 | // is not necessarily sensible, but follows GCC. |
| 861 | if (types::isObjC(InputType) && |
| 862 | Args.hasFlag(options::OPT_fobjc_exceptions, |
| 863 | options::OPT_fno_objc_exceptions, |
| 864 | true)) { |
| 865 | CmdArgs.push_back("-fobjc-exceptions"); |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 866 | |
Daniel Dunbar | d47ea69 | 2011-03-17 23:28:31 +0000 | [diff] [blame] | 867 | ShouldUseExceptionTables |= |
| 868 | shouldUseExceptionTablesForObjCExceptions(Args, Triple); |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | if (types::isCXX(InputType)) { |
| 872 | bool CXXExceptionsEnabled = ExceptionsEnabled; |
| 873 | |
| 874 | if (Arg *A = Args.getLastArg(options::OPT_fcxx_exceptions, |
| 875 | options::OPT_fno_cxx_exceptions, |
| 876 | options::OPT_fexceptions, |
| 877 | options::OPT_fno_exceptions)) { |
| 878 | if (A->getOption().matches(options::OPT_fcxx_exceptions)) |
| 879 | CXXExceptionsEnabled = true; |
Chandler Carruth | 43f220f | 2011-02-28 07:25:18 +0000 | [diff] [blame] | 880 | else if (A->getOption().matches(options::OPT_fno_cxx_exceptions)) |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 881 | CXXExceptionsEnabled = false; |
| 882 | } |
| 883 | |
| 884 | if (CXXExceptionsEnabled) { |
| 885 | CmdArgs.push_back("-fcxx-exceptions"); |
| 886 | |
| 887 | ShouldUseExceptionTables = true; |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | if (ShouldUseExceptionTables) |
| 892 | CmdArgs.push_back("-fexceptions"); |
Rafael Espindola | f759df0 | 2009-10-01 13:33:33 +0000 | [diff] [blame] | 893 | } |
| 894 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 895 | void Clang::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 896 | const InputInfo &Output, |
Daniel Dunbar | 62cf601 | 2009-03-18 06:07:59 +0000 | [diff] [blame] | 897 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 898 | const ArgList &Args, |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 899 | const char *LinkingOutput) const { |
Daniel Dunbar | 0a80ba7 | 2010-03-20 04:52:14 +0000 | [diff] [blame] | 900 | bool KernelOrKext = Args.hasArg(options::OPT_mkernel, |
| 901 | options::OPT_fapple_kext); |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 902 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 903 | ArgStringList CmdArgs; |
| 904 | |
Daniel Dunbar | 077ba6a | 2009-03-31 20:53:55 +0000 | [diff] [blame] | 905 | assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); |
| 906 | |
Daniel Dunbar | 8ff5b28 | 2009-12-11 23:00:49 +0000 | [diff] [blame] | 907 | // Invoke ourselves in -cc1 mode. |
| 908 | // |
| 909 | // FIXME: Implement custom jobs for internal actions. |
| 910 | CmdArgs.push_back("-cc1"); |
| 911 | |
Daniel Dunbar | dd4fe00 | 2009-10-30 18:12:20 +0000 | [diff] [blame] | 912 | // Add the "effective" target triple. |
Daniel Dunbar | af07f93 | 2009-03-31 17:35:15 +0000 | [diff] [blame] | 913 | CmdArgs.push_back("-triple"); |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 914 | std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); |
Daniel Dunbar | dd4fe00 | 2009-10-30 18:12:20 +0000 | [diff] [blame] | 915 | CmdArgs.push_back(Args.MakeArgString(TripleStr)); |
Daniel Dunbar | 728a512 | 2009-09-10 06:49:20 +0000 | [diff] [blame] | 916 | |
Daniel Dunbar | dd4fe00 | 2009-10-30 18:12:20 +0000 | [diff] [blame] | 917 | // Select the appropriate action. |
Daniel Dunbar | 5314e44 | 2010-07-19 19:44:22 +0000 | [diff] [blame] | 918 | bool IsRewriter = false; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 919 | if (isa<AnalyzeJobAction>(JA)) { |
| 920 | assert(JA.getType() == types::TY_Plist && "Invalid output type."); |
| 921 | CmdArgs.push_back("-analyze"); |
| 922 | } else if (isa<PreprocessJobAction>(JA)) { |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 923 | if (Output.getType() == types::TY_Dependencies) |
| 924 | CmdArgs.push_back("-Eonly"); |
| 925 | else |
| 926 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 8767cbc | 2010-02-03 03:07:56 +0000 | [diff] [blame] | 927 | } else if (isa<AssembleJobAction>(JA)) { |
| 928 | CmdArgs.push_back("-emit-obj"); |
Daniel Dunbar | 9929800 | 2010-05-27 06:18:05 +0000 | [diff] [blame] | 929 | |
| 930 | // At -O0, we use -mrelax-all by default. |
| 931 | bool IsOpt = false; |
| 932 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) |
| 933 | IsOpt = !A->getOption().matches(options::OPT_O0); |
| 934 | if (Args.hasFlag(options::OPT_mrelax_all, |
| 935 | options::OPT_mno_relax_all, |
| 936 | !IsOpt)) |
| 937 | CmdArgs.push_back("-mrelax-all"); |
Daniel Dunbar | ca0e054 | 2010-08-24 16:47:49 +0000 | [diff] [blame] | 938 | |
Daniel Dunbar | fcec10b | 2010-10-18 22:36:15 +0000 | [diff] [blame] | 939 | // When using an integrated assembler, translate -Wa, and -Xassembler |
| 940 | // options. |
| 941 | for (arg_iterator it = Args.filtered_begin(options::OPT_Wa_COMMA, |
| 942 | options::OPT_Xassembler), |
| 943 | ie = Args.filtered_end(); it != ie; ++it) { |
| 944 | const Arg *A = *it; |
| 945 | A->claim(); |
| 946 | |
| 947 | for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) { |
| 948 | llvm::StringRef Value = A->getValue(Args, i); |
| 949 | |
| 950 | if (Value == "-force_cpusubtype_ALL") { |
| 951 | // Do nothing, this is the default and we don't support anything else. |
Daniel Dunbar | b14eed0 | 2010-10-28 20:36:23 +0000 | [diff] [blame] | 952 | } else if (Value == "-L") { |
Daniel Dunbar | 9693232 | 2011-03-28 22:49:28 +0000 | [diff] [blame^] | 953 | CmdArgs.push_back("-msave-temp-labels"); |
Daniel Dunbar | fcec10b | 2010-10-18 22:36:15 +0000 | [diff] [blame] | 954 | } else { |
| 955 | D.Diag(clang::diag::err_drv_unsupported_option_argument) |
| 956 | << A->getOption().getName() << Value; |
| 957 | } |
| 958 | } |
| 959 | } |
Daniel Dunbar | d02bba8 | 2010-11-19 16:23:35 +0000 | [diff] [blame] | 960 | |
| 961 | // Also ignore explicit -force_cpusubtype_ALL option. |
| 962 | (void) Args.hasArg(options::OPT_force__cpusubtype__ALL); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 963 | } else if (isa<PrecompileJobAction>(JA)) { |
Argyrios Kyrtzidis | e5c3537 | 2010-08-11 23:27:58 +0000 | [diff] [blame] | 964 | // Use PCH if the user requested it. |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 965 | bool UsePCH = D.CCCUsePCH; |
Daniel Dunbar | 0ebd932 | 2009-10-15 20:02:44 +0000 | [diff] [blame] | 966 | |
| 967 | if (UsePCH) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 968 | CmdArgs.push_back("-emit-pch"); |
| 969 | else |
| 970 | CmdArgs.push_back("-emit-pth"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 971 | } else { |
| 972 | assert(isa<CompileJobAction>(JA) && "Invalid action for clang tool."); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 973 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 974 | if (JA.getType() == types::TY_Nothing) { |
| 975 | CmdArgs.push_back("-fsyntax-only"); |
Daniel Dunbar | 6c6424b | 2010-06-07 23:28:45 +0000 | [diff] [blame] | 976 | } else if (JA.getType() == types::TY_LLVM_IR || |
| 977 | JA.getType() == types::TY_LTO_IR) { |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 978 | CmdArgs.push_back("-emit-llvm"); |
Daniel Dunbar | 6c6424b | 2010-06-07 23:28:45 +0000 | [diff] [blame] | 979 | } else if (JA.getType() == types::TY_LLVM_BC || |
| 980 | JA.getType() == types::TY_LTO_BC) { |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 981 | CmdArgs.push_back("-emit-llvm-bc"); |
| 982 | } else if (JA.getType() == types::TY_PP_Asm) { |
Daniel Dunbar | e3b8d07 | 2009-09-17 00:47:53 +0000 | [diff] [blame] | 983 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 984 | } else if (JA.getType() == types::TY_AST) { |
| 985 | CmdArgs.push_back("-emit-pch"); |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 986 | } else if (JA.getType() == types::TY_RewrittenObjC) { |
| 987 | CmdArgs.push_back("-rewrite-objc"); |
Daniel Dunbar | 5314e44 | 2010-07-19 19:44:22 +0000 | [diff] [blame] | 988 | IsRewriter = true; |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 989 | } else { |
| 990 | assert(JA.getType() == types::TY_PP_Asm && |
| 991 | "Unexpected output type!"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 992 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 995 | // The make clang go fast button. |
| 996 | CmdArgs.push_back("-disable-free"); |
| 997 | |
John McCall | b689afb | 2010-02-13 03:50:24 +0000 | [diff] [blame] | 998 | // Disable the verification pass in -asserts builds. |
| 999 | #ifdef NDEBUG |
| 1000 | CmdArgs.push_back("-disable-llvm-verifier"); |
| 1001 | #endif |
| 1002 | |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 1003 | // Set the main file name, so that debug info works even with |
| 1004 | // -save-temps. |
| 1005 | CmdArgs.push_back("-main-file-name"); |
| 1006 | CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs)); |
| 1007 | |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 1008 | // Some flags which affect the language (via preprocessor |
| 1009 | // defines). See darwin::CC1::AddCPPArgs. |
| 1010 | if (Args.hasArg(options::OPT_static)) |
| 1011 | CmdArgs.push_back("-static-define"); |
| 1012 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1013 | if (isa<AnalyzeJobAction>(JA)) { |
Ted Kremenek | b8bb3e7 | 2009-09-25 05:55:59 +0000 | [diff] [blame] | 1014 | // Enable region store model by default. |
| 1015 | CmdArgs.push_back("-analyzer-store=region"); |
| 1016 | |
Ted Kremenek | b40d06d | 2009-12-07 22:26:14 +0000 | [diff] [blame] | 1017 | // Treat blocks as analysis entry points. |
| 1018 | CmdArgs.push_back("-analyzer-opt-analyze-nested-blocks"); |
| 1019 | |
Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1020 | CmdArgs.push_back("-analyzer-eagerly-assume"); |
| 1021 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1022 | // Add default argument set. |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 1023 | if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) { |
Argyrios Kyrtzidis | 027a6ab | 2011-02-15 07:42:33 +0000 | [diff] [blame] | 1024 | CmdArgs.push_back("-analyzer-checker=core"); |
Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1025 | CmdArgs.push_back("-analyzer-checker=deadcode"); |
| 1026 | CmdArgs.push_back("-analyzer-checker=security"); |
| 1027 | |
Argyrios Kyrtzidis | 027a6ab | 2011-02-15 07:42:33 +0000 | [diff] [blame] | 1028 | if (getToolChain().getTriple().getOS() != llvm::Triple::Win32) |
| 1029 | CmdArgs.push_back("-analyzer-checker=unix"); |
Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1030 | |
Argyrios Kyrtzidis | 027a6ab | 2011-02-15 07:42:33 +0000 | [diff] [blame] | 1031 | if (getToolChain().getTriple().getVendor() == llvm::Triple::Apple) |
Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1032 | CmdArgs.push_back("-analyzer-checker=osx"); |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 1033 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1034 | |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 1035 | // Set the output format. The default is plist, for (lame) historical |
| 1036 | // reasons. |
| 1037 | CmdArgs.push_back("-analyzer-output"); |
| 1038 | if (Arg *A = Args.getLastArg(options::OPT__analyzer_output)) |
| 1039 | CmdArgs.push_back(A->getValue(Args)); |
| 1040 | else |
| 1041 | CmdArgs.push_back("plist"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1042 | |
Ted Kremenek | 0647a7b | 2010-03-22 22:32:05 +0000 | [diff] [blame] | 1043 | // Disable the presentation of standard compiler warnings when |
| 1044 | // using --analyze. We only want to show static analyzer diagnostics |
| 1045 | // or frontend errors. |
| 1046 | CmdArgs.push_back("-w"); |
| 1047 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1048 | // Add -Xanalyzer arguments when running as analyzer. |
| 1049 | Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
Daniel Dunbar | e2fd664 | 2009-09-10 01:21:12 +0000 | [diff] [blame] | 1052 | CheckCodeGenerationOptions(D, Args); |
| 1053 | |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1054 | // Perform argument translation for LLVM backend. This |
| 1055 | // takes some care in reconciling with llvm-gcc. The |
| 1056 | // issue is that llvm-gcc translates these options based on |
| 1057 | // the values in cc1, whereas we are processing based on |
| 1058 | // the driver arguments. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1059 | |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1060 | // This comes from the default translation the driver + cc1 |
| 1061 | // would do to enable flag_pic. |
| 1062 | // |
| 1063 | // FIXME: Centralize this code. |
| 1064 | bool PICEnabled = (Args.hasArg(options::OPT_fPIC) || |
| 1065 | Args.hasArg(options::OPT_fpic) || |
| 1066 | Args.hasArg(options::OPT_fPIE) || |
| 1067 | Args.hasArg(options::OPT_fpie)); |
| 1068 | bool PICDisabled = (Args.hasArg(options::OPT_mkernel) || |
| 1069 | Args.hasArg(options::OPT_static)); |
| 1070 | const char *Model = getToolChain().GetForcedPicModel(); |
| 1071 | if (!Model) { |
| 1072 | if (Args.hasArg(options::OPT_mdynamic_no_pic)) |
| 1073 | Model = "dynamic-no-pic"; |
| 1074 | else if (PICDisabled) |
| 1075 | Model = "static"; |
| 1076 | else if (PICEnabled) |
| 1077 | Model = "pic"; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1078 | else |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1079 | Model = getToolChain().GetDefaultRelocationModel(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1080 | } |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1081 | if (llvm::StringRef(Model) != "pic") { |
| 1082 | CmdArgs.push_back("-mrelocation-model"); |
| 1083 | CmdArgs.push_back(Model); |
| 1084 | } |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1085 | |
| 1086 | // Infer the __PIC__ value. |
| 1087 | // |
| 1088 | // FIXME: This isn't quite right on Darwin, which always sets |
| 1089 | // __PIC__=2. |
| 1090 | if (strcmp(Model, "pic") == 0 || strcmp(Model, "dynamic-no-pic") == 0) { |
Daniel Dunbar | 7674352 | 2009-11-29 02:39:08 +0000 | [diff] [blame] | 1091 | CmdArgs.push_back("-pic-level"); |
| 1092 | CmdArgs.push_back(Args.hasArg(options::OPT_fPIC) ? "2" : "1"); |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1093 | } |
Tanya Lattner | 59876c2 | 2009-11-04 01:18:09 +0000 | [diff] [blame] | 1094 | if (!Args.hasFlag(options::OPT_fmerge_all_constants, |
| 1095 | options::OPT_fno_merge_all_constants)) |
Daniel Dunbar | 66861e0 | 2009-11-20 22:21:36 +0000 | [diff] [blame] | 1096 | CmdArgs.push_back("-no-merge-all-constants"); |
Daniel Dunbar | 6bea73b | 2009-09-16 06:17:29 +0000 | [diff] [blame] | 1097 | |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1098 | // LLVM Code Generator Options. |
| 1099 | |
Daniel Dunbar | 17d3fea | 2011-02-09 17:54:19 +0000 | [diff] [blame] | 1100 | if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) { |
| 1101 | CmdArgs.push_back("-mregparm"); |
| 1102 | CmdArgs.push_back(A->getValue(Args)); |
| 1103 | } |
| 1104 | |
Roman Divacky | cfe9af2 | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 1105 | if (Args.hasFlag(options::OPT_mrtd, options::OPT_mno_rtd, false)) |
| 1106 | CmdArgs.push_back("-mrtd"); |
| 1107 | |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1108 | // FIXME: Set --enable-unsafe-fp-math. |
| 1109 | if (Args.hasFlag(options::OPT_fno_omit_frame_pointer, |
| 1110 | options::OPT_fomit_frame_pointer)) |
| 1111 | CmdArgs.push_back("-mdisable-fp-elim"); |
| 1112 | if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss, |
| 1113 | options::OPT_fno_zero_initialized_in_bss)) |
| 1114 | CmdArgs.push_back("-mno-zero-initialized-in-bss"); |
Daniel Dunbar | 398c610 | 2011-02-04 02:20:39 +0000 | [diff] [blame] | 1115 | if (!Args.hasFlag(options::OPT_fstrict_aliasing, |
| 1116 | options::OPT_fno_strict_aliasing, |
| 1117 | getToolChain().IsStrictAliasingDefault())) |
Dan Gohman | 4d5625e | 2010-10-14 22:36:56 +0000 | [diff] [blame] | 1118 | CmdArgs.push_back("-relaxed-aliasing"); |
Daniel Dunbar | 1b71848 | 2010-05-14 22:00:22 +0000 | [diff] [blame] | 1119 | |
| 1120 | // Decide whether to use verbose asm. Verbose assembly is the default on |
| 1121 | // toolchains which have the integrated assembler on by default. |
| 1122 | bool IsVerboseAsmDefault = getToolChain().IsIntegratedAssemblerDefault(); |
| 1123 | if (Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm, |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1124 | IsVerboseAsmDefault) || |
Daniel Dunbar | 1b71848 | 2010-05-14 22:00:22 +0000 | [diff] [blame] | 1125 | Args.hasArg(options::OPT_dA)) |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1126 | CmdArgs.push_back("-masm-verbose"); |
Daniel Dunbar | 1b71848 | 2010-05-14 22:00:22 +0000 | [diff] [blame] | 1127 | |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1128 | if (Args.hasArg(options::OPT_fdebug_pass_structure)) { |
| 1129 | CmdArgs.push_back("-mdebug-pass"); |
| 1130 | CmdArgs.push_back("Structure"); |
| 1131 | } |
| 1132 | if (Args.hasArg(options::OPT_fdebug_pass_arguments)) { |
| 1133 | CmdArgs.push_back("-mdebug-pass"); |
| 1134 | CmdArgs.push_back("Arguments"); |
| 1135 | } |
| 1136 | |
John McCall | d0c2ec4 | 2010-02-19 02:45:38 +0000 | [diff] [blame] | 1137 | // Enable -mconstructor-aliases except on darwin, where we have to |
| 1138 | // work around a linker bug; see <rdar://problem/7651567>. |
| 1139 | if (getToolChain().getTriple().getOS() != llvm::Triple::Darwin) |
| 1140 | CmdArgs.push_back("-mconstructor-aliases"); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 1141 | |
John McCall | 3209669 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 1142 | // Darwin's kernel doesn't support guard variables; just die if we |
| 1143 | // try to use them. |
| 1144 | if (KernelOrKext && |
| 1145 | getToolChain().getTriple().getOS() == llvm::Triple::Darwin) |
| 1146 | CmdArgs.push_back("-fforbid-guard-variables"); |
| 1147 | |
Douglas Gregor | 6f75550 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 1148 | if (Args.hasArg(options::OPT_mms_bitfields)) { |
| 1149 | CmdArgs.push_back("-mms-bitfields"); |
| 1150 | } |
John McCall | d0c2ec4 | 2010-02-19 02:45:38 +0000 | [diff] [blame] | 1151 | |
Daniel Dunbar | 6bea73b | 2009-09-16 06:17:29 +0000 | [diff] [blame] | 1152 | // This is a coarse approximation of what llvm-gcc actually does, both |
| 1153 | // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more |
| 1154 | // complicated ways. |
| 1155 | bool AsynchronousUnwindTables = |
| 1156 | Args.hasFlag(options::OPT_fasynchronous_unwind_tables, |
| 1157 | options::OPT_fno_asynchronous_unwind_tables, |
| 1158 | getToolChain().IsUnwindTablesDefault() && |
Daniel Dunbar | 0a80ba7 | 2010-03-20 04:52:14 +0000 | [diff] [blame] | 1159 | !KernelOrKext); |
Daniel Dunbar | 6bea73b | 2009-09-16 06:17:29 +0000 | [diff] [blame] | 1160 | if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables, |
| 1161 | AsynchronousUnwindTables)) |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1162 | CmdArgs.push_back("-munwind-tables"); |
| 1163 | |
| 1164 | if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) { |
| 1165 | CmdArgs.push_back("-mlimit-float-precision"); |
| 1166 | CmdArgs.push_back(A->getValue(Args)); |
| 1167 | } |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1168 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1169 | // FIXME: Handle -mtune=. |
| 1170 | (void) Args.hasArg(options::OPT_mtune_EQ); |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1171 | |
Benjamin Kramer | 8e9ef0d | 2009-08-05 14:30:52 +0000 | [diff] [blame] | 1172 | if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) { |
Daniel Dunbar | f219e7c | 2009-11-29 07:18:39 +0000 | [diff] [blame] | 1173 | CmdArgs.push_back("-mcode-model"); |
Benjamin Kramer | 8e9ef0d | 2009-08-05 14:30:52 +0000 | [diff] [blame] | 1174 | CmdArgs.push_back(A->getValue(Args)); |
| 1175 | } |
| 1176 | |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1177 | // Add target specific cpu and features flags. |
| 1178 | switch(getToolChain().getTriple().getArch()) { |
| 1179 | default: |
| 1180 | break; |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 1181 | |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 1182 | case llvm::Triple::arm: |
| 1183 | case llvm::Triple::thumb: |
Daniel Dunbar | fa41d69 | 2011-03-17 17:10:06 +0000 | [diff] [blame] | 1184 | AddARMTargetArgs(Args, CmdArgs, KernelOrKext); |
Daniel Dunbar | b163ef7 | 2009-09-10 04:57:17 +0000 | [diff] [blame] | 1185 | break; |
| 1186 | |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 1187 | case llvm::Triple::mips: |
| 1188 | case llvm::Triple::mipsel: |
| 1189 | AddMIPSTargetArgs(Args, CmdArgs); |
| 1190 | break; |
| 1191 | |
Bruno Cardoso Lopes | 9284d21 | 2010-11-09 17:21:19 +0000 | [diff] [blame] | 1192 | case llvm::Triple::sparc: |
| 1193 | AddSparcTargetArgs(Args, CmdArgs); |
| 1194 | break; |
| 1195 | |
Daniel Dunbar | 6acda16 | 2009-09-09 22:33:08 +0000 | [diff] [blame] | 1196 | case llvm::Triple::x86: |
| 1197 | case llvm::Triple::x86_64: |
| 1198 | AddX86TargetArgs(Args, CmdArgs); |
| 1199 | break; |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Daniel Dunbar | c176bc6 | 2010-08-11 23:07:47 +0000 | [diff] [blame] | 1202 | // Pass the linker version in use. |
| 1203 | if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { |
| 1204 | CmdArgs.push_back("-target-linker-version"); |
| 1205 | CmdArgs.push_back(A->getValue(Args)); |
| 1206 | } |
| 1207 | |
Nick Lewycky | b2d11cc | 2011-02-02 06:43:03 +0000 | [diff] [blame] | 1208 | // -mno-omit-leaf-frame-pointer is the default on Darwin. |
Daniel Dunbar | 1ad6648 | 2010-07-01 01:31:45 +0000 | [diff] [blame] | 1209 | if (Args.hasFlag(options::OPT_momit_leaf_frame_pointer, |
Nick Lewycky | b2d11cc | 2011-02-02 06:43:03 +0000 | [diff] [blame] | 1210 | options::OPT_mno_omit_leaf_frame_pointer, |
| 1211 | getToolChain().getTriple().getOS() != llvm::Triple::Darwin)) |
Daniel Dunbar | 1ad6648 | 2010-07-01 01:31:45 +0000 | [diff] [blame] | 1212 | CmdArgs.push_back("-momit-leaf-frame-pointer"); |
| 1213 | |
Dan Gohman | c31176d | 2010-01-08 02:20:44 +0000 | [diff] [blame] | 1214 | // -fno-math-errno is default. |
| 1215 | if (Args.hasFlag(options::OPT_fmath_errno, |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1216 | options::OPT_fno_math_errno, |
Dan Gohman | c31176d | 2010-01-08 02:20:44 +0000 | [diff] [blame] | 1217 | false)) |
| 1218 | CmdArgs.push_back("-fmath-errno"); |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 1219 | |
Daniel Dunbar | b30575c | 2010-05-12 18:19:58 +0000 | [diff] [blame] | 1220 | // Explicitly error on some things we know we don't support and can't just |
| 1221 | // ignore. |
| 1222 | types::ID InputType = Inputs[0].getType(); |
Daniel Dunbar | e94db47 | 2010-09-24 19:39:37 +0000 | [diff] [blame] | 1223 | if (!Args.hasArg(options::OPT_fallow_unsupported)) { |
| 1224 | Arg *Unsupported; |
| 1225 | if ((Unsupported = Args.getLastArg(options::OPT_MG)) || |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 1226 | (Unsupported = Args.getLastArg(options::OPT_iframework))) |
Daniel Dunbar | e94db47 | 2010-09-24 19:39:37 +0000 | [diff] [blame] | 1227 | D.Diag(clang::diag::err_drv_clang_unsupported) |
Daniel Dunbar | b30575c | 2010-05-12 18:19:58 +0000 | [diff] [blame] | 1228 | << Unsupported->getOption().getName(); |
Daniel Dunbar | e94db47 | 2010-09-24 19:39:37 +0000 | [diff] [blame] | 1229 | |
| 1230 | if (types::isCXX(InputType) && |
| 1231 | getToolChain().getTriple().getOS() == llvm::Triple::Darwin && |
| 1232 | getToolChain().getTriple().getArch() == llvm::Triple::x86) { |
| 1233 | if ((Unsupported = Args.getLastArg(options::OPT_fapple_kext))) |
| 1234 | D.Diag(clang::diag::err_drv_clang_unsupported_opt_cxx_darwin_i386) |
| 1235 | << Unsupported->getOption().getName(); |
| 1236 | } |
Daniel Dunbar | b30575c | 2010-05-12 18:19:58 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1239 | Args.AddAllArgs(CmdArgs, options::OPT_v); |
Daniel Dunbar | f7c16d9 | 2010-08-24 22:44:13 +0000 | [diff] [blame] | 1240 | Args.AddLastArg(CmdArgs, options::OPT_H); |
Daniel Dunbar | 322c29f | 2011-02-02 21:11:35 +0000 | [diff] [blame] | 1241 | if (D.CCPrintHeaders) { |
| 1242 | CmdArgs.push_back("-header-include-file"); |
| 1243 | CmdArgs.push_back(D.CCPrintHeadersFilename ? |
| 1244 | D.CCPrintHeadersFilename : "-"); |
| 1245 | } |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1246 | Args.AddLastArg(CmdArgs, options::OPT_P); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1248 | |
| 1249 | // Special case debug options to only pass -g to clang. This is |
| 1250 | // wrong. |
Rafael Espindola | 18f36d9 | 2010-03-07 04:46:18 +0000 | [diff] [blame] | 1251 | Args.ClaimAllArgs(options::OPT_g_Group); |
Daniel Dunbar | 6b3d5a6 | 2010-05-12 18:19:55 +0000 | [diff] [blame] | 1252 | if (Arg *A = Args.getLastArg(options::OPT_g_Group)) |
| 1253 | if (!A->getOption().matches(options::OPT_g0)) |
| 1254 | CmdArgs.push_back("-g"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1255 | |
Rafael Espindola | 9cf933a | 2010-05-06 21:06:04 +0000 | [diff] [blame] | 1256 | Args.AddAllArgs(CmdArgs, options::OPT_ffunction_sections); |
| 1257 | Args.AddAllArgs(CmdArgs, options::OPT_fdata_sections); |
| 1258 | |
Chris Lattner | 7255a2d | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 1259 | Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions); |
| 1260 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1261 | Args.AddLastArg(CmdArgs, options::OPT_nostdinc); |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 1262 | Args.AddLastArg(CmdArgs, options::OPT_nostdincxx); |
Rafael Espindola | 8d737cc | 2009-10-26 13:36:57 +0000 | [diff] [blame] | 1263 | Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1264 | |
Daniel Dunbar | 5f12232 | 2009-12-15 01:02:52 +0000 | [diff] [blame] | 1265 | // Pass the path to compiler resource files. |
Daniel Dunbar | 5f12232 | 2009-12-15 01:02:52 +0000 | [diff] [blame] | 1266 | CmdArgs.push_back("-resource-dir"); |
Daniel Dunbar | 225c417 | 2010-01-20 02:35:16 +0000 | [diff] [blame] | 1267 | CmdArgs.push_back(D.ResourceDir.c_str()); |
Daniel Dunbar | 2ac9fc2 | 2009-04-07 21:42:00 +0000 | [diff] [blame] | 1268 | |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 1269 | Args.AddLastArg(CmdArgs, options::OPT_working_directory); |
| 1270 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1271 | // Add preprocessing options like -I, -D, etc. if we are using the |
| 1272 | // preprocessor. |
| 1273 | // |
| 1274 | // FIXME: Support -fpreprocessed |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1275 | if (types::getPreprocessedType(InputType) != types::TY_INVALID) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 1276 | AddPreprocessingOptions(D, Args, CmdArgs, Output, Inputs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1277 | |
Daniel Dunbar | 20f0eac | 2009-09-17 06:53:36 +0000 | [diff] [blame] | 1278 | // Manually translate -O to -O2 and -O4 to -O3; let clang reject |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 1279 | // others. |
| 1280 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
Daniel Dunbar | b827a05 | 2009-11-19 03:26:40 +0000 | [diff] [blame] | 1281 | if (A->getOption().matches(options::OPT_O4)) |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 1282 | CmdArgs.push_back("-O3"); |
Daniel Dunbar | 473916c | 2010-05-27 06:51:08 +0000 | [diff] [blame] | 1283 | else if (A->getOption().matches(options::OPT_O) && |
| 1284 | A->getValue(Args)[0] == '\0') |
Daniel Dunbar | 20f0eac | 2009-09-17 06:53:36 +0000 | [diff] [blame] | 1285 | CmdArgs.push_back("-O2"); |
Daniel Dunbar | 5e3bc94 | 2010-11-13 18:17:11 +0000 | [diff] [blame] | 1286 | else if (A->getOption().matches(options::OPT_O) && |
| 1287 | A->getValue(Args)[0] == 'z' && |
| 1288 | A->getValue(Args)[1] == '\0') |
| 1289 | CmdArgs.push_back("-Os"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1290 | else |
Daniel Dunbar | 5697aa0 | 2009-03-18 23:39:35 +0000 | [diff] [blame] | 1291 | A->render(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
Daniel Dunbar | 6e8371e | 2009-10-29 02:24:45 +0000 | [diff] [blame] | 1294 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group); |
| 1295 | Args.AddLastArg(CmdArgs, options::OPT_pedantic); |
| 1296 | Args.AddLastArg(CmdArgs, options::OPT_pedantic_errors); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1297 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 1298 | |
| 1299 | // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi} |
| 1300 | // (-ansi is equivalent to -std=c89). |
| 1301 | // |
| 1302 | // If a std is supplied, only add -trigraphs if it follows the |
| 1303 | // option. |
| 1304 | if (Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { |
| 1305 | if (Std->getOption().matches(options::OPT_ansi)) |
Nuno Lopes | 528365d | 2009-10-16 14:28:06 +0000 | [diff] [blame] | 1306 | if (types::isCXX(InputType)) |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 1307 | CmdArgs.push_back("-std=c++98"); |
Nuno Lopes | 528365d | 2009-10-16 14:28:06 +0000 | [diff] [blame] | 1308 | else |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 1309 | CmdArgs.push_back("-std=c89"); |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 1310 | else |
| 1311 | Std->render(Args, CmdArgs); |
| 1312 | |
Daniel Dunbar | 0e10031 | 2010-06-14 21:23:08 +0000 | [diff] [blame] | 1313 | if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi, |
| 1314 | options::OPT_trigraphs)) |
| 1315 | if (A != Std) |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 1316 | A->render(Args, CmdArgs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 1317 | } else { |
| 1318 | // Honor -std-default. |
Daniel Dunbar | 4a5290e | 2010-01-29 21:03:02 +0000 | [diff] [blame] | 1319 | // |
| 1320 | // FIXME: Clang doesn't correctly handle -std= when the input language |
| 1321 | // doesn't match. For the time being just ignore this for C++ inputs; |
| 1322 | // eventually we want to do all the standard defaulting here instead of |
| 1323 | // splitting it between the driver and clang -cc1. |
| 1324 | if (!types::isCXX(InputType)) |
| 1325 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, |
| 1326 | "-std=", /*Joined=*/true); |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 1327 | Args.AddLastArg(CmdArgs, options::OPT_trigraphs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 1328 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1329 | |
Chandler Carruth | c304ba3 | 2010-05-22 02:21:53 +0000 | [diff] [blame] | 1330 | // Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'. |
| 1331 | if (Arg *Asm = Args.getLastArg(options::OPT_fasm, options::OPT_fno_asm)) { |
| 1332 | if (Asm->getOption().matches(options::OPT_fasm)) |
| 1333 | CmdArgs.push_back("-fgnu-keywords"); |
| 1334 | else |
| 1335 | CmdArgs.push_back("-fno-gnu-keywords"); |
| 1336 | } |
| 1337 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1338 | if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) { |
| 1339 | CmdArgs.push_back("-ftemplate-depth"); |
| 1340 | CmdArgs.push_back(A->getValue(Args)); |
| 1341 | } |
| 1342 | |
Argyrios Kyrtzidis | 1380a14 | 2010-11-18 00:20:36 +0000 | [diff] [blame] | 1343 | if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ, |
| 1344 | options::OPT_Wlarge_by_value_copy_def)) { |
| 1345 | CmdArgs.push_back("-Wlarge-by-value-copy"); |
Argyrios Kyrtzidis | 3532fdd | 2010-11-17 23:11:54 +0000 | [diff] [blame] | 1346 | if (A->getNumValues()) |
| 1347 | CmdArgs.push_back(A->getValue(Args)); |
| 1348 | else |
Argyrios Kyrtzidis | 1380a14 | 2010-11-18 00:20:36 +0000 | [diff] [blame] | 1349 | CmdArgs.push_back("64"); // default value for -Wlarge-by-value-copy. |
Argyrios Kyrtzidis | 3532fdd | 2010-11-17 23:11:54 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
Daniel Dunbar | e4bdae7 | 2009-11-19 04:00:53 +0000 | [diff] [blame] | 1352 | if (Args.hasArg(options::OPT__relocatable_pch)) |
Daniel Dunbar | 66861e0 | 2009-11-20 22:21:36 +0000 | [diff] [blame] | 1353 | CmdArgs.push_back("-relocatable-pch"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1354 | |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 1355 | if (Arg *A = Args.getLastArg(options::OPT_fconstant_string_class_EQ)) { |
| 1356 | CmdArgs.push_back("-fconstant-string-class"); |
| 1357 | CmdArgs.push_back(A->getValue(Args)); |
| 1358 | } |
David Chisnall | 8a5a9aa | 2009-08-31 16:41:57 +0000 | [diff] [blame] | 1359 | |
Chris Lattner | 124fca5 | 2010-01-09 21:54:33 +0000 | [diff] [blame] | 1360 | if (Arg *A = Args.getLastArg(options::OPT_ftabstop_EQ)) { |
| 1361 | CmdArgs.push_back("-ftabstop"); |
| 1362 | CmdArgs.push_back(A->getValue(Args)); |
| 1363 | } |
| 1364 | |
Chris Lattner | 0f0c963 | 2010-04-07 20:49:23 +0000 | [diff] [blame] | 1365 | CmdArgs.push_back("-ferror-limit"); |
| 1366 | if (Arg *A = Args.getLastArg(options::OPT_ferror_limit_EQ)) |
| 1367 | CmdArgs.push_back(A->getValue(Args)); |
| 1368 | else |
| 1369 | CmdArgs.push_back("19"); |
Douglas Gregor | 575cf37 | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 1370 | |
Chandler Carruth | c40f73c | 2010-05-06 04:55:18 +0000 | [diff] [blame] | 1371 | if (Arg *A = Args.getLastArg(options::OPT_fmacro_backtrace_limit_EQ)) { |
| 1372 | CmdArgs.push_back("-fmacro-backtrace-limit"); |
Douglas Gregor | 6c1cb99 | 2010-05-04 17:13:42 +0000 | [diff] [blame] | 1373 | CmdArgs.push_back(A->getValue(Args)); |
Chandler Carruth | c40f73c | 2010-05-06 04:55:18 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | if (Arg *A = Args.getLastArg(options::OPT_ftemplate_backtrace_limit_EQ)) { |
| 1377 | CmdArgs.push_back("-ftemplate-backtrace-limit"); |
Douglas Gregor | 575cf37 | 2010-04-20 07:18:24 +0000 | [diff] [blame] | 1378 | CmdArgs.push_back(A->getValue(Args)); |
Chandler Carruth | c40f73c | 2010-05-06 04:55:18 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
Daniel Dunbar | 55efe14 | 2009-11-04 06:24:47 +0000 | [diff] [blame] | 1381 | // Pass -fmessage-length=. |
Daniel Dunbar | a28690e | 2009-11-30 08:40:54 +0000 | [diff] [blame] | 1382 | CmdArgs.push_back("-fmessage-length"); |
Daniel Dunbar | 55efe14 | 2009-11-04 06:24:47 +0000 | [diff] [blame] | 1383 | if (Arg *A = Args.getLastArg(options::OPT_fmessage_length_EQ)) { |
Daniel Dunbar | a28690e | 2009-11-30 08:40:54 +0000 | [diff] [blame] | 1384 | CmdArgs.push_back(A->getValue(Args)); |
Daniel Dunbar | 55efe14 | 2009-11-04 06:24:47 +0000 | [diff] [blame] | 1385 | } else { |
| 1386 | // If -fmessage-length=N was not specified, determine whether this is a |
| 1387 | // terminal and, if so, implicitly define -fmessage-length appropriately. |
| 1388 | unsigned N = llvm::sys::Process::StandardErrColumns(); |
Daniel Dunbar | 55efe14 | 2009-11-04 06:24:47 +0000 | [diff] [blame] | 1389 | CmdArgs.push_back(Args.MakeArgString(llvm::Twine(N))); |
| 1390 | } |
| 1391 | |
Daniel Dunbar | ba8d861 | 2009-12-03 18:42:11 +0000 | [diff] [blame] | 1392 | if (const Arg *A = Args.getLastArg(options::OPT_fvisibility_EQ)) { |
| 1393 | CmdArgs.push_back("-fvisibility"); |
| 1394 | CmdArgs.push_back(A->getValue(Args)); |
| 1395 | } |
| 1396 | |
Douglas Gregor | 7cf84d6 | 2010-06-15 17:05:35 +0000 | [diff] [blame] | 1397 | Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1398 | |
Daniel Dunbar | 0a80ba7 | 2010-03-20 04:52:14 +0000 | [diff] [blame] | 1399 | // -fhosted is default. |
| 1400 | if (KernelOrKext || Args.hasFlag(options::OPT_ffreestanding, |
| 1401 | options::OPT_fhosted, |
| 1402 | false)) |
| 1403 | CmdArgs.push_back("-ffreestanding"); |
| 1404 | |
Daniel Dunbar | ba8d861 | 2009-12-03 18:42:11 +0000 | [diff] [blame] | 1405 | // Forward -f (flag) options which we can pass directly. |
Mike Stump | 9c276ae | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 1406 | Args.AddLastArg(CmdArgs, options::OPT_fcatch_undefined_behavior); |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 1407 | Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 1408 | Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); |
Devang Patel | c69e1cf | 2010-09-30 19:05:55 +0000 | [diff] [blame] | 1409 | Args.AddLastArg(CmdArgs, options::OPT_flimit_debug_info); |
Daniel Dunbar | bbe8e3e | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 1410 | if (getToolChain().SupportsProfiling()) |
| 1411 | Args.AddLastArg(CmdArgs, options::OPT_pg); |
Daniel Dunbar | 8c6fa84 | 2010-03-16 16:57:46 +0000 | [diff] [blame] | 1412 | |
| 1413 | // -flax-vector-conversions is default. |
| 1414 | if (!Args.hasFlag(options::OPT_flax_vector_conversions, |
| 1415 | options::OPT_fno_lax_vector_conversions)) |
| 1416 | CmdArgs.push_back("-fno-lax-vector-conversions"); |
| 1417 | |
Daniel Dunbar | 43a9b32 | 2010-04-10 16:20:23 +0000 | [diff] [blame] | 1418 | // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only |
| 1419 | // takes precedence. |
| 1420 | const Arg *GCArg = Args.getLastArg(options::OPT_fobjc_gc_only); |
| 1421 | if (!GCArg) |
| 1422 | GCArg = Args.getLastArg(options::OPT_fobjc_gc); |
| 1423 | if (GCArg) { |
| 1424 | if (getToolChain().SupportsObjCGC()) { |
| 1425 | GCArg->render(Args, CmdArgs); |
| 1426 | } else { |
| 1427 | // FIXME: We should move this to a hard error. |
| 1428 | D.Diag(clang::diag::warn_drv_objc_gc_unsupported) |
| 1429 | << GCArg->getAsString(Args); |
| 1430 | } |
| 1431 | } |
| 1432 | |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 1433 | if (Args.getLastArg(options::OPT_fapple_kext)) |
| 1434 | CmdArgs.push_back("-fapple-kext"); |
| 1435 | |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 1436 | Args.AddLastArg(CmdArgs, options::OPT_fno_show_column); |
Fariborz Jahanian | 34e6577 | 2009-05-22 20:17:16 +0000 | [diff] [blame] | 1437 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch); |
Chris Lattner | 182e092 | 2009-04-21 05:34:31 +0000 | [diff] [blame] | 1438 | Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info); |
Douglas Gregor | 4786c15 | 2010-08-19 20:24:43 +0000 | [diff] [blame] | 1439 | Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits); |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 1440 | Args.AddLastArg(CmdArgs, options::OPT_ftime_report); |
| 1441 | Args.AddLastArg(CmdArgs, options::OPT_ftrapv); |
David Chisnall | 7f18e67 | 2010-09-17 18:29:54 +0000 | [diff] [blame] | 1442 | |
| 1443 | if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) { |
| 1444 | CmdArgs.push_back("-ftrapv-handler"); |
| 1445 | CmdArgs.push_back(A->getValue(Args)); |
| 1446 | } |
| 1447 | |
Chandler Carruth | 5adb5a8 | 2011-03-27 00:04:55 +0000 | [diff] [blame] | 1448 | // -fno-strict-overflow implies -fwrapv if it isn't disabled, but |
| 1449 | // -fstrict-overflow won't turn off an explicitly enabled -fwrapv. |
| 1450 | if (Arg *A = Args.getLastArg(options::OPT_fwrapv, |
| 1451 | options::OPT_fno_wrapv)) { |
| 1452 | if (A->getOption().matches(options::OPT_fwrapv)) |
| 1453 | CmdArgs.push_back("-fwrapv"); |
| 1454 | } else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow, |
| 1455 | options::OPT_fno_strict_overflow)) { |
| 1456 | if (A->getOption().matches(options::OPT_fno_strict_overflow)) |
| 1457 | CmdArgs.push_back("-fwrapv"); |
| 1458 | } |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 1459 | Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings); |
Eric Christopher | f84d409 | 2010-08-07 23:08:14 +0000 | [diff] [blame] | 1460 | Args.AddLastArg(CmdArgs, options::OPT_funroll_loops); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1461 | |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 1462 | Args.AddLastArg(CmdArgs, options::OPT_pthread); |
| 1463 | |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 1464 | // -stack-protector=0 is default. |
| 1465 | unsigned StackProtectorLevel = 0; |
Bill Wendling | 45483f7 | 2009-06-28 07:36:13 +0000 | [diff] [blame] | 1466 | if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector, |
| 1467 | options::OPT_fstack_protector_all, |
| 1468 | options::OPT_fstack_protector)) { |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 1469 | if (A->getOption().matches(options::OPT_fstack_protector)) |
| 1470 | StackProtectorLevel = 1; |
| 1471 | else if (A->getOption().matches(options::OPT_fstack_protector_all)) |
| 1472 | StackProtectorLevel = 2; |
| 1473 | } else |
| 1474 | StackProtectorLevel = getToolChain().GetDefaultStackProtectorLevel(); |
| 1475 | if (StackProtectorLevel) { |
| 1476 | CmdArgs.push_back("-stack-protector"); |
| 1477 | CmdArgs.push_back(Args.MakeArgString(llvm::Twine(StackProtectorLevel))); |
Bill Wendling | 45483f7 | 2009-06-28 07:36:13 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 1480 | // Forward -f options with positive and negative forms; we translate |
| 1481 | // these by hand. |
| 1482 | |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 1483 | if (Args.hasArg(options::OPT_mkernel)) { |
Daniel Dunbar | 2843c19 | 2011-02-04 17:24:47 +0000 | [diff] [blame] | 1484 | if (!Args.hasArg(options::OPT_fapple_kext) && types::isCXX(InputType)) |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 1485 | CmdArgs.push_back("-fapple-kext"); |
| 1486 | if (!Args.hasArg(options::OPT_fbuiltin)) |
| 1487 | CmdArgs.push_back("-fno-builtin"); |
| 1488 | } |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 1489 | // -fbuiltin is default. |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 1490 | else if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin)) |
Daniel Dunbar | 53e8484 | 2009-11-19 04:55:23 +0000 | [diff] [blame] | 1491 | CmdArgs.push_back("-fno-builtin"); |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 1492 | |
Nuno Lopes | fc28448 | 2009-12-16 16:59:22 +0000 | [diff] [blame] | 1493 | if (!Args.hasFlag(options::OPT_fassume_sane_operator_new, |
| 1494 | options::OPT_fno_assume_sane_operator_new)) |
| 1495 | CmdArgs.push_back("-fno-assume-sane-operator-new"); |
| 1496 | |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 1497 | // -fblocks=0 is default. |
| 1498 | if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks, |
David Chisnall | e6533ff | 2011-02-28 17:11:43 +0000 | [diff] [blame] | 1499 | getToolChain().IsBlocksDefault()) || |
| 1500 | (Args.hasArg(options::OPT_fgnu_runtime) && |
| 1501 | Args.hasArg(options::OPT_fobjc_nonfragile_abi) && |
| 1502 | !Args.hasArg(options::OPT_fno_blocks))) { |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 1503 | CmdArgs.push_back("-fblocks"); |
David Chisnall | 5e530af | 2009-11-17 19:33:30 +0000 | [diff] [blame] | 1504 | } |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 1505 | |
John McCall | 32579cf | 2010-04-09 19:12:06 +0000 | [diff] [blame] | 1506 | // -faccess-control is default. |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 1507 | if (Args.hasFlag(options::OPT_fno_access_control, |
| 1508 | options::OPT_faccess_control, |
John McCall | 32579cf | 2010-04-09 19:12:06 +0000 | [diff] [blame] | 1509 | false)) |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 1510 | CmdArgs.push_back("-fno-access-control"); |
John McCall | 3ddd6e0 | 2010-03-17 01:32:13 +0000 | [diff] [blame] | 1511 | |
Anders Carlsson | a4c2475 | 2010-11-21 00:09:52 +0000 | [diff] [blame] | 1512 | // -felide-constructors is the default. |
| 1513 | if (Args.hasFlag(options::OPT_fno_elide_constructors, |
| 1514 | options::OPT_felide_constructors, |
| 1515 | false)) |
| 1516 | CmdArgs.push_back("-fno-elide-constructors"); |
| 1517 | |
Anders Carlsson | 15348ae | 2011-02-28 02:27:16 +0000 | [diff] [blame] | 1518 | // Add exception args. |
| 1519 | addExceptionArgs(Args, InputType, getToolChain().getTriple(), |
| 1520 | KernelOrKext, IsRewriter, CmdArgs); |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 1521 | |
Daniel Dunbar | b2987d1 | 2010-02-10 18:49:11 +0000 | [diff] [blame] | 1522 | if (getToolChain().UseSjLjExceptions()) |
| 1523 | CmdArgs.push_back("-fsjlj-exceptions"); |
| 1524 | |
Daniel Dunbar | 0be42c4 | 2009-11-17 07:06:20 +0000 | [diff] [blame] | 1525 | // -frtti is default. |
Daniel Dunbar | 0a80ba7 | 2010-03-20 04:52:14 +0000 | [diff] [blame] | 1526 | if (KernelOrKext || |
| 1527 | !Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti)) |
Daniel Dunbar | 53e8484 | 2009-11-19 04:55:23 +0000 | [diff] [blame] | 1528 | CmdArgs.push_back("-fno-rtti"); |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 1529 | |
Argyrios Kyrtzidis | 9a2b9d7 | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 1530 | // -fshort-enums=0 is default. |
| 1531 | // FIXME: Are there targers where -fshort-enums is on by default ? |
| 1532 | if (Args.hasFlag(options::OPT_fshort_enums, |
| 1533 | options::OPT_fno_short_enums, false)) |
| 1534 | CmdArgs.push_back("-fshort-enums"); |
| 1535 | |
Daniel Dunbar | 1f95e65 | 2009-11-17 06:37:03 +0000 | [diff] [blame] | 1536 | // -fsigned-char is default. |
Daniel Dunbar | 6d2eb4d | 2009-11-25 10:14:30 +0000 | [diff] [blame] | 1537 | if (!Args.hasFlag(options::OPT_fsigned_char, options::OPT_funsigned_char, |
Daniel Dunbar | 1f95e65 | 2009-11-17 06:37:03 +0000 | [diff] [blame] | 1538 | isSignedCharDefault(getToolChain().getTriple()))) |
Daniel Dunbar | 7674352 | 2009-11-29 02:39:08 +0000 | [diff] [blame] | 1539 | CmdArgs.push_back("-fno-signed-char"); |
Eli Friedman | 5a77973 | 2009-06-05 07:21:14 +0000 | [diff] [blame] | 1540 | |
Anders Carlsson | a508b7d | 2010-02-06 23:23:06 +0000 | [diff] [blame] | 1541 | // -fthreadsafe-static is default. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1542 | if (!Args.hasFlag(options::OPT_fthreadsafe_statics, |
Anders Carlsson | a508b7d | 2010-02-06 23:23:06 +0000 | [diff] [blame] | 1543 | options::OPT_fno_threadsafe_statics)) |
| 1544 | CmdArgs.push_back("-fno-threadsafe-statics"); |
| 1545 | |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 1546 | // -fuse-cxa-atexit is default. |
Anton Korobeynikov | d0a57d5 | 2010-09-11 11:17:06 +0000 | [diff] [blame] | 1547 | if (KernelOrKext || |
| 1548 | !Args.hasFlag(options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit, |
NAKAMURA Takumi | cd7a30b | 2010-10-10 01:53:03 +0000 | [diff] [blame] | 1549 | getToolChain().getTriple().getOS() != llvm::Triple::Cygwin && |
NAKAMURA Takumi | 0aa2057 | 2011-02-17 08:51:38 +0000 | [diff] [blame] | 1550 | getToolChain().getTriple().getOS() != llvm::Triple::MinGW32)) |
Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 1551 | CmdArgs.push_back("-fno-use-cxa-atexit"); |
| 1552 | |
Daniel Dunbar | 0be42c4 | 2009-11-17 07:06:20 +0000 | [diff] [blame] | 1553 | // -fms-extensions=0 is default. |
Daniel Dunbar | 6d2eb4d | 2009-11-25 10:14:30 +0000 | [diff] [blame] | 1554 | if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions, |
Daniel Dunbar | 0be42c4 | 2009-11-17 07:06:20 +0000 | [diff] [blame] | 1555 | getToolChain().getTriple().getOS() == llvm::Triple::Win32)) |
| 1556 | CmdArgs.push_back("-fms-extensions"); |
| 1557 | |
Michael J. Spencer | dae4ac4 | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 1558 | // -fmsc-version=1300 is default. |
| 1559 | if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions, |
| 1560 | getToolChain().getTriple().getOS() == llvm::Triple::Win32) || |
| 1561 | Args.hasArg(options::OPT_fmsc_version)) { |
| 1562 | llvm::StringRef msc_ver = Args.getLastArgValue(options::OPT_fmsc_version); |
| 1563 | if (msc_ver.empty()) |
| 1564 | CmdArgs.push_back("-fmsc-version=1300"); |
| 1565 | else |
| 1566 | CmdArgs.push_back(Args.MakeArgString("-fmsc-version=" + msc_ver)); |
| 1567 | } |
| 1568 | |
| 1569 | |
Dawn Perchik | 400b607 | 2010-09-02 23:59:25 +0000 | [diff] [blame] | 1570 | // -fborland-extensions=0 is default. |
| 1571 | if (Args.hasFlag(options::OPT_fborland_extensions, |
| 1572 | options::OPT_fno_borland_extensions, false)) |
| 1573 | CmdArgs.push_back("-fborland-extensions"); |
| 1574 | |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 1575 | // -fgnu-keywords default varies depending on language; only pass if |
| 1576 | // specified. |
| 1577 | if (Arg *A = Args.getLastArg(options::OPT_fgnu_keywords, |
Daniel Dunbar | 40788d9 | 2010-04-24 17:56:39 +0000 | [diff] [blame] | 1578 | options::OPT_fno_gnu_keywords)) |
| 1579 | A->render(Args, CmdArgs); |
Chandler Carruth | eb5d7b7 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 1580 | |
Daniel Dunbar | 5314e44 | 2010-07-19 19:44:22 +0000 | [diff] [blame] | 1581 | // -fnext-runtime defaults to on Darwin and when rewriting Objective-C, and is |
| 1582 | // -the -cc1 default. |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1583 | bool NeXTRuntimeIsDefault = |
Daniel Dunbar | 5314e44 | 2010-07-19 19:44:22 +0000 | [diff] [blame] | 1584 | IsRewriter || getToolChain().getTriple().getOS() == llvm::Triple::Darwin; |
Daniel Dunbar | 6d2eb4d | 2009-11-25 10:14:30 +0000 | [diff] [blame] | 1585 | if (!Args.hasFlag(options::OPT_fnext_runtime, options::OPT_fgnu_runtime, |
Daniel Dunbar | 5314e44 | 2010-07-19 19:44:22 +0000 | [diff] [blame] | 1586 | NeXTRuntimeIsDefault)) |
Daniel Dunbar | c5a97ec | 2009-11-17 07:07:28 +0000 | [diff] [blame] | 1587 | CmdArgs.push_back("-fgnu-runtime"); |
| 1588 | |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 1589 | // -fobjc-nonfragile-abi=0 is default. |
| 1590 | if (types::isObjC(InputType)) { |
Daniel Dunbar | dea6313 | 2010-09-20 18:19:55 +0000 | [diff] [blame] | 1591 | // Compute the Objective-C ABI "version" to use. Version numbers are |
| 1592 | // slightly confusing for historical reasons: |
| 1593 | // 1 - Traditional "fragile" ABI |
| 1594 | // 2 - Non-fragile ABI, version 1 |
| 1595 | // 3 - Non-fragile ABI, version 2 |
Daniel Dunbar | 5e2a8ac | 2010-04-28 23:25:24 +0000 | [diff] [blame] | 1596 | unsigned Version = 1; |
Daniel Dunbar | dea6313 | 2010-09-20 18:19:55 +0000 | [diff] [blame] | 1597 | // If -fobjc-abi-version= is present, use that to set the version. |
Daniel Dunbar | 5e2a8ac | 2010-04-28 23:25:24 +0000 | [diff] [blame] | 1598 | if (Arg *A = Args.getLastArg(options::OPT_fobjc_abi_version_EQ)) { |
| 1599 | if (llvm::StringRef(A->getValue(Args)) == "1") |
| 1600 | Version = 1; |
| 1601 | else if (llvm::StringRef(A->getValue(Args)) == "2") |
| 1602 | Version = 2; |
Fariborz Jahanian | 5f81d8a | 2010-09-15 16:00:51 +0000 | [diff] [blame] | 1603 | else if (llvm::StringRef(A->getValue(Args)) == "3") |
| 1604 | Version = 3; |
Daniel Dunbar | 5e2a8ac | 2010-04-28 23:25:24 +0000 | [diff] [blame] | 1605 | else |
| 1606 | D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args); |
Daniel Dunbar | dea6313 | 2010-09-20 18:19:55 +0000 | [diff] [blame] | 1607 | } else { |
| 1608 | // Otherwise, determine if we are using the non-fragile ABI. |
| 1609 | if (Args.hasFlag(options::OPT_fobjc_nonfragile_abi, |
| 1610 | options::OPT_fno_objc_nonfragile_abi, |
| 1611 | getToolChain().IsObjCNonFragileABIDefault())) { |
| 1612 | // Determine the non-fragile ABI version to use. |
Daniel Dunbar | de17ba7 | 2010-11-11 16:08:59 +0000 | [diff] [blame] | 1613 | #ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO |
| 1614 | unsigned NonFragileABIVersion = 1; |
| 1615 | #else |
Daniel Dunbar | dea6313 | 2010-09-20 18:19:55 +0000 | [diff] [blame] | 1616 | unsigned NonFragileABIVersion = 2; |
Daniel Dunbar | de17ba7 | 2010-11-11 16:08:59 +0000 | [diff] [blame] | 1617 | #endif |
Daniel Dunbar | dea6313 | 2010-09-20 18:19:55 +0000 | [diff] [blame] | 1618 | |
| 1619 | if (Arg *A = Args.getLastArg( |
| 1620 | options::OPT_fobjc_nonfragile_abi_version_EQ)) { |
| 1621 | if (llvm::StringRef(A->getValue(Args)) == "1") |
| 1622 | NonFragileABIVersion = 1; |
| 1623 | else if (llvm::StringRef(A->getValue(Args)) == "2") |
| 1624 | NonFragileABIVersion = 2; |
| 1625 | else |
| 1626 | D.Diag(clang::diag::err_drv_clang_unsupported) |
| 1627 | << A->getAsString(Args); |
| 1628 | } |
| 1629 | |
| 1630 | Version = 1 + NonFragileABIVersion; |
| 1631 | } else { |
| 1632 | Version = 1; |
| 1633 | } |
Daniel Dunbar | 5e2a8ac | 2010-04-28 23:25:24 +0000 | [diff] [blame] | 1634 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1635 | |
Fariborz Jahanian | 5f81d8a | 2010-09-15 16:00:51 +0000 | [diff] [blame] | 1636 | if (Version == 2 || Version == 3) { |
Fariborz Jahanian | 112c330 | 2011-01-04 20:05:20 +0000 | [diff] [blame] | 1637 | CmdArgs.push_back("-fobjc-nonfragile-abi"); |
Daniel Dunbar | f643b9b | 2010-04-24 17:56:46 +0000 | [diff] [blame] | 1638 | |
| 1639 | // -fobjc-dispatch-method is only relevant with the nonfragile-abi, and |
| 1640 | // legacy is the default. |
| 1641 | if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch, |
| 1642 | options::OPT_fno_objc_legacy_dispatch, |
| 1643 | getToolChain().IsObjCLegacyDispatchDefault())) { |
| 1644 | if (getToolChain().UseObjCMixedDispatch()) |
| 1645 | CmdArgs.push_back("-fobjc-dispatch-method=mixed"); |
| 1646 | else |
| 1647 | CmdArgs.push_back("-fobjc-dispatch-method=non-legacy"); |
| 1648 | } |
Daniel Dunbar | 984eb86 | 2010-02-01 21:07:25 +0000 | [diff] [blame] | 1649 | } |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 1650 | |
Ted Kremenek | c32647d | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 1651 | // -fobjc-default-synthesize-properties=0 is default. |
| 1652 | if (Args.hasFlag(options::OPT_fobjc_default_synthesize_properties, |
| 1653 | options::OPT_fno_objc_default_synthesize_properties, |
| 1654 | getToolChain().IsObjCDefaultSynthPropertiesDefault())) { |
| 1655 | CmdArgs.push_back("-fobjc-default-synthesize-properties"); |
| 1656 | } |
Daniel Dunbar | 9e5cc6b | 2009-11-17 08:07:36 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
Daniel Dunbar | 984eb86 | 2010-02-01 21:07:25 +0000 | [diff] [blame] | 1659 | if (!Args.hasFlag(options::OPT_fassume_sane_operator_new, |
| 1660 | options::OPT_fno_assume_sane_operator_new)) |
| 1661 | CmdArgs.push_back("-fno-assume-sane-operator-new"); |
| 1662 | |
Daniel Dunbar | f35f14d | 2010-04-27 15:34:57 +0000 | [diff] [blame] | 1663 | // -fconstant-cfstrings is default, and may be subject to argument translation |
| 1664 | // on Darwin. |
| 1665 | if (!Args.hasFlag(options::OPT_fconstant_cfstrings, |
| 1666 | options::OPT_fno_constant_cfstrings) || |
| 1667 | !Args.hasFlag(options::OPT_mconstant_cfstrings, |
| 1668 | options::OPT_mno_constant_cfstrings)) |
| 1669 | CmdArgs.push_back("-fno-constant-cfstrings"); |
| 1670 | |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 1671 | // -fshort-wchar default varies depending on platform; only |
| 1672 | // pass if specified. |
Daniel Dunbar | 1744a35 | 2010-04-27 15:35:03 +0000 | [diff] [blame] | 1673 | if (Arg *A = Args.getLastArg(options::OPT_fshort_wchar)) |
| 1674 | A->render(Args, CmdArgs); |
John Thompson | a6fda12 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 1675 | |
Daniel Dunbar | ee848a7 | 2009-10-29 02:39:57 +0000 | [diff] [blame] | 1676 | // -fno-pascal-strings is default, only pass non-default. If the tool chain |
| 1677 | // happened to translate to -mpascal-strings, we want to back translate here. |
Daniel Dunbar | 82d0068 | 2009-04-07 23:51:44 +0000 | [diff] [blame] | 1678 | // |
| 1679 | // FIXME: This is gross; that translation should be pulled from the |
| 1680 | // tool chain. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1681 | if (Args.hasFlag(options::OPT_fpascal_strings, |
Daniel Dunbar | 82d0068 | 2009-04-07 23:51:44 +0000 | [diff] [blame] | 1682 | options::OPT_fno_pascal_strings, |
| 1683 | false) || |
| 1684 | Args.hasFlag(options::OPT_mpascal_strings, |
| 1685 | options::OPT_mno_pascal_strings, |
| 1686 | false)) |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 1687 | CmdArgs.push_back("-fpascal-strings"); |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 1688 | |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 1689 | if (Args.hasArg(options::OPT_mkernel) || |
| 1690 | Args.hasArg(options::OPT_fapple_kext)) { |
| 1691 | if (!Args.hasArg(options::OPT_fcommon)) |
| 1692 | CmdArgs.push_back("-fno-common"); |
| 1693 | } |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 1694 | // -fcommon is default, only pass non-default. |
Fariborz Jahanian | b466d01 | 2011-01-07 01:05:02 +0000 | [diff] [blame] | 1695 | else if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common)) |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 1696 | CmdArgs.push_back("-fno-common"); |
| 1697 | |
Daniel Dunbar | 70d3c92 | 2009-04-15 02:37:43 +0000 | [diff] [blame] | 1698 | // -fsigned-bitfields is default, and clang doesn't yet support |
Daniel Dunbar | 06205ca | 2010-10-15 22:30:42 +0000 | [diff] [blame] | 1699 | // -funsigned-bitfields. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1700 | if (!Args.hasFlag(options::OPT_fsigned_bitfields, |
Daniel Dunbar | 70d3c92 | 2009-04-15 02:37:43 +0000 | [diff] [blame] | 1701 | options::OPT_funsigned_bitfields)) |
| 1702 | D.Diag(clang::diag::warn_drv_clang_unsupported) |
| 1703 | << Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args); |
| 1704 | |
Daniel Dunbar | 06205ca | 2010-10-15 22:30:42 +0000 | [diff] [blame] | 1705 | // -fsigned-bitfields is default, and clang doesn't support -fno-for-scope. |
| 1706 | if (!Args.hasFlag(options::OPT_ffor_scope, |
| 1707 | options::OPT_fno_for_scope)) |
| 1708 | D.Diag(clang::diag::err_drv_clang_unsupported) |
| 1709 | << Args.getLastArg(options::OPT_fno_for_scope)->getAsString(Args); |
| 1710 | |
Jeffrey Yasskin | 0ea22fd | 2010-06-08 04:56:20 +0000 | [diff] [blame] | 1711 | // -fcaret-diagnostics is default. |
| 1712 | if (!Args.hasFlag(options::OPT_fcaret_diagnostics, |
| 1713 | options::OPT_fno_caret_diagnostics, true)) |
| 1714 | CmdArgs.push_back("-fno-caret-diagnostics"); |
| 1715 | |
Daniel Dunbar | 49138fc | 2009-04-19 21:09:34 +0000 | [diff] [blame] | 1716 | // -fdiagnostics-fixit-info is default, only pass non-default. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1717 | if (!Args.hasFlag(options::OPT_fdiagnostics_fixit_info, |
Daniel Dunbar | 49138fc | 2009-04-19 21:09:34 +0000 | [diff] [blame] | 1718 | options::OPT_fno_diagnostics_fixit_info)) |
| 1719 | CmdArgs.push_back("-fno-diagnostics-fixit-info"); |
| 1720 | |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 1721 | // Enable -fdiagnostics-show-option by default. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1722 | if (Args.hasFlag(options::OPT_fdiagnostics_show_option, |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 1723 | options::OPT_fno_diagnostics_show_option)) |
| 1724 | CmdArgs.push_back("-fdiagnostics-show-option"); |
Daniel Dunbar | 838be48 | 2009-11-04 06:24:57 +0000 | [diff] [blame] | 1725 | |
Chris Lattner | 6fbe839 | 2010-05-04 21:55:25 +0000 | [diff] [blame] | 1726 | if (const Arg *A = |
| 1727 | Args.getLastArg(options::OPT_fdiagnostics_show_category_EQ)) { |
| 1728 | CmdArgs.push_back("-fdiagnostics-show-category"); |
| 1729 | CmdArgs.push_back(A->getValue(Args)); |
| 1730 | } |
Daniel Dunbar | ca0e054 | 2010-08-24 16:47:49 +0000 | [diff] [blame] | 1731 | |
Chandler Carruth | abaca7a | 2011-03-27 01:50:55 +0000 | [diff] [blame] | 1732 | if (Arg *A = Args.getLastArg( |
| 1733 | options::OPT_fdiagnostics_show_note_include_stack, |
| 1734 | options::OPT_fno_diagnostics_show_note_include_stack)) { |
| 1735 | if (A->getOption().matches( |
| 1736 | options::OPT_fdiagnostics_show_note_include_stack)) |
| 1737 | CmdArgs.push_back("-fdiagnostics-show-note-include-stack"); |
| 1738 | else |
| 1739 | CmdArgs.push_back("-fno-diagnostics-show-note-include-stack"); |
| 1740 | } |
| 1741 | |
Daniel Dunbar | 838be48 | 2009-11-04 06:24:57 +0000 | [diff] [blame] | 1742 | // Color diagnostics are the default, unless the terminal doesn't support |
| 1743 | // them. |
| 1744 | if (Args.hasFlag(options::OPT_fcolor_diagnostics, |
Argyrios Kyrtzidis | f765d76 | 2010-09-23 12:56:06 +0000 | [diff] [blame] | 1745 | options::OPT_fno_color_diagnostics, |
| 1746 | llvm::sys::Process::StandardErrHasColors())) |
Daniel Dunbar | 838be48 | 2009-11-04 06:24:57 +0000 | [diff] [blame] | 1747 | CmdArgs.push_back("-fcolor-diagnostics"); |
| 1748 | |
Daniel Dunbar | 75eb1d6 | 2009-06-08 21:13:54 +0000 | [diff] [blame] | 1749 | if (!Args.hasFlag(options::OPT_fshow_source_location, |
| 1750 | options::OPT_fno_show_source_location)) |
| 1751 | CmdArgs.push_back("-fno-show-source-location"); |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 1752 | |
Douglas Gregor | a0068fc | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 1753 | if (!Args.hasFlag(options::OPT_fspell_checking, |
| 1754 | options::OPT_fno_spell_checking)) |
| 1755 | CmdArgs.push_back("-fno-spell-checking"); |
Daniel Dunbar | ca0e054 | 2010-08-24 16:47:49 +0000 | [diff] [blame] | 1756 | |
Daniel Dunbar | 25b26eb | 2010-10-18 22:49:46 +0000 | [diff] [blame] | 1757 | |
Daniel Dunbar | 1689439 | 2010-11-02 19:42:04 +0000 | [diff] [blame] | 1758 | // Silently ignore -fasm-blocks for now. |
| 1759 | (void) Args.hasFlag(options::OPT_fasm_blocks, options::OPT_fno_asm_blocks, |
| 1760 | false); |
Daniel Dunbar | 25b26eb | 2010-10-18 22:49:46 +0000 | [diff] [blame] | 1761 | |
Jeffrey Yasskin | 5edbdcc | 2010-06-11 05:57:47 +0000 | [diff] [blame] | 1762 | if (Arg *A = Args.getLastArg(options::OPT_fshow_overloads_EQ)) |
| 1763 | A->render(Args, CmdArgs); |
| 1764 | |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 1765 | // -fdollars-in-identifiers default varies depending on platform and |
| 1766 | // language; only pass if specified. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1767 | if (Arg *A = Args.getLastArg(options::OPT_fdollars_in_identifiers, |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 1768 | options::OPT_fno_dollars_in_identifiers)) { |
| 1769 | if (A->getOption().matches(options::OPT_fdollars_in_identifiers)) |
Daniel Dunbar | 8663b18 | 2009-12-16 20:10:18 +0000 | [diff] [blame] | 1770 | CmdArgs.push_back("-fdollars-in-identifiers"); |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 1771 | else |
Daniel Dunbar | 8663b18 | 2009-12-16 20:10:18 +0000 | [diff] [blame] | 1772 | CmdArgs.push_back("-fno-dollars-in-identifiers"); |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
Daniel Dunbar | e027a4b | 2009-05-22 19:02:20 +0000 | [diff] [blame] | 1775 | // -funit-at-a-time is default, and we don't support -fno-unit-at-a-time for |
| 1776 | // practical purposes. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1777 | if (Arg *A = Args.getLastArg(options::OPT_funit_at_a_time, |
Daniel Dunbar | e027a4b | 2009-05-22 19:02:20 +0000 | [diff] [blame] | 1778 | options::OPT_fno_unit_at_a_time)) { |
| 1779 | if (A->getOption().matches(options::OPT_fno_unit_at_a_time)) |
Edward O'Callaghan | c376910 | 2009-10-13 16:41:34 +0000 | [diff] [blame] | 1780 | D.Diag(clang::diag::warn_drv_clang_unsupported) << A->getAsString(Args); |
Daniel Dunbar | e027a4b | 2009-05-22 19:02:20 +0000 | [diff] [blame] | 1781 | } |
Eli Friedman | ceb5c5b | 2009-07-14 21:58:17 +0000 | [diff] [blame] | 1782 | |
Daniel Dunbar | 2ba9157 | 2009-09-10 03:37:02 +0000 | [diff] [blame] | 1783 | // Default to -fno-builtin-str{cat,cpy} on Darwin for ARM. |
Daniel Dunbar | f84a4a4 | 2009-09-10 04:57:27 +0000 | [diff] [blame] | 1784 | // |
Daniel Dunbar | 8ff5b28 | 2009-12-11 23:00:49 +0000 | [diff] [blame] | 1785 | // FIXME: This is disabled until clang -cc1 supports -fno-builtin-foo. PR4941. |
Daniel Dunbar | f84a4a4 | 2009-09-10 04:57:27 +0000 | [diff] [blame] | 1786 | #if 0 |
Daniel Dunbar | 2ba9157 | 2009-09-10 03:37:02 +0000 | [diff] [blame] | 1787 | if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin && |
| 1788 | (getToolChain().getTriple().getArch() == llvm::Triple::arm || |
| 1789 | getToolChain().getTriple().getArch() == llvm::Triple::thumb)) { |
| 1790 | if (!Args.hasArg(options::OPT_fbuiltin_strcat)) |
| 1791 | CmdArgs.push_back("-fno-builtin-strcat"); |
| 1792 | if (!Args.hasArg(options::OPT_fbuiltin_strcpy)) |
| 1793 | CmdArgs.push_back("-fno-builtin-strcpy"); |
| 1794 | } |
Daniel Dunbar | f84a4a4 | 2009-09-10 04:57:27 +0000 | [diff] [blame] | 1795 | #endif |
Daniel Dunbar | 2ba9157 | 2009-09-10 03:37:02 +0000 | [diff] [blame] | 1796 | |
Daniel Dunbar | d98750f | 2011-03-18 21:23:40 +0000 | [diff] [blame] | 1797 | // Only allow -traditional or -traditional-cpp outside in preprocessing modes. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1798 | if (Arg *A = Args.getLastArg(options::OPT_traditional, |
Daniel Dunbar | d98750f | 2011-03-18 21:23:40 +0000 | [diff] [blame] | 1799 | options::OPT_traditional_cpp)) { |
| 1800 | if (isa<PreprocessJobAction>(JA)) |
| 1801 | CmdArgs.push_back("-traditional-cpp"); |
| 1802 | else |
| 1803 | D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args); |
| 1804 | } |
Eli Friedman | ceb5c5b | 2009-07-14 21:58:17 +0000 | [diff] [blame] | 1805 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1806 | Args.AddLastArg(CmdArgs, options::OPT_dM); |
Chris Lattner | d82df3a | 2009-04-12 01:56:53 +0000 | [diff] [blame] | 1807 | Args.AddLastArg(CmdArgs, options::OPT_dD); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1808 | |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 1809 | // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option |
| 1810 | // parser. |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1811 | Args.AddAllArgValues(CmdArgs, options::OPT_Xclang); |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 1812 | for (arg_iterator it = Args.filtered_begin(options::OPT_mllvm), |
| 1813 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1814 | (*it)->claim(); |
Daniel Dunbar | fb36d21 | 2010-04-17 06:10:00 +0000 | [diff] [blame] | 1815 | |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 1816 | // We translate this by hand to the -cc1 argument, since nightly test uses |
| 1817 | // it and developers have been trained to spell it with -mllvm. |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1818 | if (llvm::StringRef((*it)->getValue(Args, 0)) == "-disable-llvm-optzns") |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 1819 | CmdArgs.push_back("-disable-llvm-optzns"); |
| 1820 | else |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 1821 | (*it)->render(Args, CmdArgs); |
Daniel Dunbar | 3f87fb0 | 2010-04-15 06:09:03 +0000 | [diff] [blame] | 1822 | } |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1823 | |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 1824 | if (Output.getType() == types::TY_Dependencies) { |
| 1825 | // Handled with other dependency code. |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 1826 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1827 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 1828 | CmdArgs.push_back(Output.getFilename()); |
| 1829 | } else { |
| 1830 | assert(Output.isNothing() && "Invalid output."); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1833 | for (InputInfoList::const_iterator |
| 1834 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1835 | const InputInfo &II = *it; |
| 1836 | CmdArgs.push_back("-x"); |
| 1837 | CmdArgs.push_back(types::getTypeName(II.getType())); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 1838 | if (II.isFilename()) |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 1839 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1840 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 1841 | II.getInputArg().renderAsInput(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1842 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1843 | |
Chris Lattner | e6113de | 2009-11-03 19:50:27 +0000 | [diff] [blame] | 1844 | Args.AddAllArgs(CmdArgs, options::OPT_undef); |
| 1845 | |
Daniel Dunbar | a001c1c | 2010-07-18 21:16:15 +0000 | [diff] [blame] | 1846 | const char *Exec = getToolChain().getDriver().getClangProgramPath(); |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1847 | |
| 1848 | // Optionally embed the -cc1 level arguments into the debug info, for build |
| 1849 | // analysis. |
| 1850 | if (getToolChain().UseDwarfDebugFlags()) { |
Daniel Dunbar | 6e90047 | 2010-06-04 18:47:06 +0000 | [diff] [blame] | 1851 | ArgStringList OriginalArgs; |
| 1852 | for (ArgList::const_iterator it = Args.begin(), |
| 1853 | ie = Args.end(); it != ie; ++it) |
| 1854 | (*it)->render(Args, OriginalArgs); |
Daniel Dunbar | ca0e054 | 2010-08-24 16:47:49 +0000 | [diff] [blame] | 1855 | |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1856 | llvm::SmallString<256> Flags; |
| 1857 | Flags += Exec; |
Daniel Dunbar | 6e90047 | 2010-06-04 18:47:06 +0000 | [diff] [blame] | 1858 | for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) { |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1859 | Flags += " "; |
Daniel Dunbar | 6e90047 | 2010-06-04 18:47:06 +0000 | [diff] [blame] | 1860 | Flags += OriginalArgs[i]; |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 1861 | } |
| 1862 | CmdArgs.push_back("-dwarf-debug-flags"); |
| 1863 | CmdArgs.push_back(Args.MakeArgString(Flags.str())); |
| 1864 | } |
| 1865 | |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 1866 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 1867 | |
Roman Divacky | be4c870 | 2011-02-10 16:52:03 +0000 | [diff] [blame] | 1868 | if (Arg *A = Args.getLastArg(options::OPT_pg)) |
| 1869 | if (Args.hasArg(options::OPT_fomit_frame_pointer)) |
| 1870 | D.Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 1871 | << "-fomit-frame-pointer" << A->getAsString(Args); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1872 | |
Daniel Dunbar | 68fb469 | 2009-04-03 20:51:31 +0000 | [diff] [blame] | 1873 | // Claim some arguments which clang supports automatically. |
| 1874 | |
Daniel Dunbar | f404686 | 2010-04-15 06:18:42 +0000 | [diff] [blame] | 1875 | // -fpch-preprocess is used with gcc to add a special marker in the output to |
| 1876 | // include the PCH file. Clang's PTH solution is completely transparent, so we |
| 1877 | // do not need to deal with it at all. |
Daniel Dunbar | 68fb469 | 2009-04-03 20:51:31 +0000 | [diff] [blame] | 1878 | Args.ClaimAllArgs(options::OPT_fpch_preprocess); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1879 | |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 1880 | // Claim some arguments which clang doesn't support, but we don't |
| 1881 | // care to warn the user about. |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 1882 | Args.ClaimAllArgs(options::OPT_clang_ignored_f_Group); |
| 1883 | Args.ClaimAllArgs(options::OPT_clang_ignored_m_Group); |
Rafael Espindola | 035ff0c | 2011-02-28 23:29:45 +0000 | [diff] [blame] | 1884 | |
Rafael Espindola | 9c094fb | 2011-03-01 05:25:27 +0000 | [diff] [blame] | 1885 | // Disable warnings for clang -E -use-gold-plugin -emit-llvm foo.c |
Rafael Espindola | 035ff0c | 2011-02-28 23:29:45 +0000 | [diff] [blame] | 1886 | Args.ClaimAllArgs(options::OPT_use_gold_plugin); |
Rafael Espindola | 9c094fb | 2011-03-01 05:25:27 +0000 | [diff] [blame] | 1887 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 1888 | } |
| 1889 | |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 1890 | void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 1891 | const InputInfo &Output, |
| 1892 | const InputInfoList &Inputs, |
| 1893 | const ArgList &Args, |
| 1894 | const char *LinkingOutput) const { |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 1895 | ArgStringList CmdArgs; |
| 1896 | |
| 1897 | assert(Inputs.size() == 1 && "Unexpected number of inputs."); |
| 1898 | const InputInfo &Input = Inputs[0]; |
| 1899 | |
Rafael Espindola | dbe80d9 | 2010-11-17 22:13:25 +0000 | [diff] [blame] | 1900 | // Don't warn about "clang -w -c foo.s" |
| 1901 | Args.ClaimAllArgs(options::OPT_w); |
Rafael Espindola | 9c094fb | 2011-03-01 05:25:27 +0000 | [diff] [blame] | 1902 | // and "clang -emit-llvm -c foo.s" |
| 1903 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
| 1904 | // and "clang -use-gold-plugin -c foo.s" |
| 1905 | Args.ClaimAllArgs(options::OPT_use_gold_plugin); |
Rafael Espindola | dbe80d9 | 2010-11-17 22:13:25 +0000 | [diff] [blame] | 1906 | |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 1907 | // Invoke ourselves in -cc1as mode. |
| 1908 | // |
| 1909 | // FIXME: Implement custom jobs for internal actions. |
| 1910 | CmdArgs.push_back("-cc1as"); |
| 1911 | |
| 1912 | // Add the "effective" target triple. |
| 1913 | CmdArgs.push_back("-triple"); |
Daniel Dunbar | 00577ad | 2010-08-23 22:35:37 +0000 | [diff] [blame] | 1914 | std::string TripleStr = getToolChain().ComputeEffectiveClangTriple(Args); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 1915 | CmdArgs.push_back(Args.MakeArgString(TripleStr)); |
| 1916 | |
| 1917 | // Set the output mode, we currently only expect to be used as a real |
| 1918 | // assembler. |
| 1919 | CmdArgs.push_back("-filetype"); |
| 1920 | CmdArgs.push_back("obj"); |
| 1921 | |
Daniel Dunbar | 9929800 | 2010-05-27 06:18:05 +0000 | [diff] [blame] | 1922 | // At -O0, we use -mrelax-all by default. |
| 1923 | bool IsOpt = false; |
| 1924 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) |
| 1925 | IsOpt = !A->getOption().matches(options::OPT_O0); |
| 1926 | if (Args.hasFlag(options::OPT_mrelax_all, |
| 1927 | options::OPT_mno_relax_all, |
| 1928 | !IsOpt)) |
Daniel Dunbar | 469d40e | 2010-05-28 16:43:21 +0000 | [diff] [blame] | 1929 | CmdArgs.push_back("-relax-all"); |
Daniel Dunbar | 9929800 | 2010-05-27 06:18:05 +0000 | [diff] [blame] | 1930 | |
Daniel Dunbar | 7f6f8c8 | 2011-03-17 17:37:29 +0000 | [diff] [blame] | 1931 | // Ignore explicit -force_cpusubtype_ALL option. |
| 1932 | (void) Args.hasArg(options::OPT_force__cpusubtype__ALL); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 1933 | |
| 1934 | // FIXME: Add -g support, once we have it. |
| 1935 | |
| 1936 | // FIXME: Add -static support, once we have it. |
| 1937 | |
| 1938 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 1939 | options::OPT_Xassembler); |
| 1940 | |
| 1941 | assert(Output.isFilename() && "Unexpected lipo output."); |
| 1942 | CmdArgs.push_back("-o"); |
| 1943 | CmdArgs.push_back(Output.getFilename()); |
| 1944 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 1945 | assert(Input.isFilename() && "Invalid input."); |
| 1946 | CmdArgs.push_back(Input.getFilename()); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 1947 | |
Daniel Dunbar | a001c1c | 2010-07-18 21:16:15 +0000 | [diff] [blame] | 1948 | const char *Exec = getToolChain().getDriver().getClangProgramPath(); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 1949 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 20a9aa5 | 2010-05-20 21:30:13 +0000 | [diff] [blame] | 1950 | } |
| 1951 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1952 | void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1953 | const InputInfo &Output, |
| 1954 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1955 | const ArgList &Args, |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1956 | const char *LinkingOutput) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 1957 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1958 | ArgStringList CmdArgs; |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 1959 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1960 | for (ArgList::const_iterator |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1961 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1962 | Arg *A = *it; |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 1963 | if (A->getOption().hasForwardToGCC()) { |
Daniel Dunbar | 2dffe2d | 2010-08-03 16:14:14 +0000 | [diff] [blame] | 1964 | // Don't forward any -g arguments to assembly steps. |
| 1965 | if (isa<AssembleJobAction>(JA) && |
| 1966 | A->getOption().matches(options::OPT_g_Group)) |
| 1967 | continue; |
| 1968 | |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 1969 | // It is unfortunate that we have to claim here, as this means |
| 1970 | // we will basically never report anything interesting for |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 1971 | // platforms using a generic gcc, even if we are just using gcc |
| 1972 | // to get to the assembler. |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 1973 | A->claim(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 1974 | A->render(Args, CmdArgs); |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 1975 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1976 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1977 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 1978 | RenderExtraToolArgs(JA, CmdArgs); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1979 | |
| 1980 | // If using a driver driver, force the arch. |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 1981 | const std::string &Arch = getToolChain().getArchName(); |
Daniel Dunbar | 1bda434 | 2009-12-23 00:46:38 +0000 | [diff] [blame] | 1982 | if (getToolChain().getTriple().getOS() == llvm::Triple::Darwin) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1983 | CmdArgs.push_back("-arch"); |
Daniel Dunbar | bf54a06 | 2009-04-01 20:33:11 +0000 | [diff] [blame] | 1984 | |
| 1985 | // FIXME: Remove these special cases. |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 1986 | if (Arch == "powerpc") |
| 1987 | CmdArgs.push_back("ppc"); |
| 1988 | else if (Arch == "powerpc64") |
| 1989 | CmdArgs.push_back("ppc64"); |
| 1990 | else |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 1991 | CmdArgs.push_back(Args.MakeArgString(Arch)); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 1994 | // Try to force gcc to match the tool chain we want, if we recognize |
| 1995 | // the arch. |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 1996 | // |
| 1997 | // FIXME: The triple class should directly provide the information we want |
| 1998 | // here. |
| 1999 | if (Arch == "i386" || Arch == "powerpc") |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 2000 | CmdArgs.push_back("-m32"); |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 2001 | else if (Arch == "x86_64" || Arch == "powerpc64") |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 2002 | CmdArgs.push_back("-m64"); |
| 2003 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 2004 | if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 2005 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 2006 | CmdArgs.push_back(Output.getFilename()); |
| 2007 | } else { |
| 2008 | assert(Output.isNothing() && "Unexpected output"); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 2009 | CmdArgs.push_back("-fsyntax-only"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 2010 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 2011 | |
| 2012 | |
| 2013 | // Only pass -x if gcc will understand it; otherwise hope gcc |
| 2014 | // understands the suffix correctly. The main use case this would go |
| 2015 | // wrong in is for linker inputs if they happened to have an odd |
| 2016 | // suffix; really the only way to get this to happen is a command |
| 2017 | // like '-x foobar a.c' which will treat a.c like a linker input. |
| 2018 | // |
| 2019 | // FIXME: For the linker case specifically, can we safely convert |
| 2020 | // inputs into '-Wl,' options? |
| 2021 | for (InputInfoList::const_iterator |
| 2022 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 2023 | const InputInfo &II = *it; |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 2024 | |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 2025 | // Don't try to pass LLVM or AST inputs to a generic gcc. |
Daniel Dunbar | 6c6424b | 2010-06-07 23:28:45 +0000 | [diff] [blame] | 2026 | if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR || |
| 2027 | II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC) |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 2028 | D.Diag(clang::diag::err_drv_no_linker_llvm_support) |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 2029 | << getToolChain().getTripleString(); |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 2030 | else if (II.getType() == types::TY_AST) |
| 2031 | D.Diag(clang::diag::err_drv_no_ast_support) |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 2032 | << getToolChain().getTripleString(); |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 2033 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 2034 | if (types::canTypeBeUserSpecified(II.getType())) { |
| 2035 | CmdArgs.push_back("-x"); |
| 2036 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 2037 | } |
| 2038 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 2039 | if (II.isFilename()) |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 2040 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 48f9994 | 2010-09-25 18:10:05 +0000 | [diff] [blame] | 2041 | else { |
| 2042 | const Arg &A = II.getInputArg(); |
| 2043 | |
| 2044 | // Reverse translate some rewritten options. |
| 2045 | if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) { |
| 2046 | CmdArgs.push_back("-lstdc++"); |
| 2047 | continue; |
| 2048 | } |
| 2049 | |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 2050 | // Don't render as input, we need gcc to do the translations. |
Daniel Dunbar | 48f9994 | 2010-09-25 18:10:05 +0000 | [diff] [blame] | 2051 | A.render(Args, CmdArgs); |
| 2052 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Rafael Espindola | 79e9e9d | 2010-09-06 02:36:23 +0000 | [diff] [blame] | 2055 | const char *GCCName = getToolChain().getDriver().getCCCGenericGCCName().c_str(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2056 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 2057 | Args.MakeArgString(getToolChain().GetProgramPath(GCCName)); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 2058 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 2061 | void gcc::Preprocess::RenderExtraToolArgs(const JobAction &JA, |
| 2062 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 2063 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 2064 | } |
| 2065 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 2066 | void gcc::Precompile::RenderExtraToolArgs(const JobAction &JA, |
| 2067 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 2068 | // The type is good enough. |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 2071 | void gcc::Compile::RenderExtraToolArgs(const JobAction &JA, |
| 2072 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 2073 | const Driver &D = getToolChain().getDriver(); |
| 2074 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 2075 | // If -flto, etc. are present then make sure not to force assembly output. |
Daniel Dunbar | 6c6424b | 2010-06-07 23:28:45 +0000 | [diff] [blame] | 2076 | if (JA.getType() == types::TY_LLVM_IR || JA.getType() == types::TY_LTO_IR || |
| 2077 | JA.getType() == types::TY_LLVM_BC || JA.getType() == types::TY_LTO_BC) |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 2078 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 2079 | else { |
| 2080 | if (JA.getType() != types::TY_PP_Asm) |
| 2081 | D.Diag(clang::diag::err_drv_invalid_gcc_output_type) |
| 2082 | << getTypeName(JA.getType()); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2083 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 2084 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 2085 | } |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 2088 | void gcc::Assemble::RenderExtraToolArgs(const JobAction &JA, |
| 2089 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 2090 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 2091 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 2092 | |
Daniel Dunbar | 82b51cc | 2010-01-25 22:35:08 +0000 | [diff] [blame] | 2093 | void gcc::Link::RenderExtraToolArgs(const JobAction &JA, |
| 2094 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 2095 | // The types are (hopefully) good enough. |
| 2096 | } |
| 2097 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2098 | const char *darwin::CC1::getCC1Name(types::ID Type) const { |
| 2099 | switch (Type) { |
| 2100 | default: |
| 2101 | assert(0 && "Unexpected type for Darwin CC1 tool."); |
| 2102 | case types::TY_Asm: |
| 2103 | case types::TY_C: case types::TY_CHeader: |
| 2104 | case types::TY_PP_C: case types::TY_PP_CHeader: |
| 2105 | return "cc1"; |
| 2106 | case types::TY_ObjC: case types::TY_ObjCHeader: |
| 2107 | case types::TY_PP_ObjC: case types::TY_PP_ObjCHeader: |
| 2108 | return "cc1obj"; |
| 2109 | case types::TY_CXX: case types::TY_CXXHeader: |
| 2110 | case types::TY_PP_CXX: case types::TY_PP_CXXHeader: |
| 2111 | return "cc1plus"; |
| 2112 | case types::TY_ObjCXX: case types::TY_ObjCXXHeader: |
| 2113 | case types::TY_PP_ObjCXX: case types::TY_PP_ObjCXXHeader: |
| 2114 | return "cc1objplus"; |
| 2115 | } |
| 2116 | } |
| 2117 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2118 | const char *darwin::CC1::getBaseInputName(const ArgList &Args, |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 2119 | const InputInfoList &Inputs) { |
Michael J. Spencer | 472ccff | 2010-12-18 00:19:12 +0000 | [diff] [blame] | 2120 | return Args.MakeArgString( |
| 2121 | llvm::sys::path::filename(Inputs[0].getBaseInput())); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2122 | } |
| 2123 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2124 | const char *darwin::CC1::getBaseInputStem(const ArgList &Args, |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 2125 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2126 | const char *Str = getBaseInputName(Args, Inputs); |
| 2127 | |
Chris Lattner | 657ca66 | 2011-01-16 08:14:11 +0000 | [diff] [blame] | 2128 | if (const char *End = strrchr(Str, '.')) |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 2129 | return Args.MakeArgString(std::string(Str, End)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2130 | |
| 2131 | return Str; |
| 2132 | } |
| 2133 | |
| 2134 | const char * |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2135 | darwin::CC1::getDependencyFileName(const ArgList &Args, |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 2136 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2137 | // FIXME: Think about this more. |
| 2138 | std::string Res; |
| 2139 | |
| 2140 | if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) { |
| 2141 | std::string Str(OutputOpt->getValue(Args)); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2142 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2143 | Res = Str.substr(0, Str.rfind('.')); |
| 2144 | } else |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 2145 | Res = darwin::CC1::getBaseInputStem(Args, Inputs); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2146 | |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 2147 | return Args.MakeArgString(Res + ".d"); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2150 | void darwin::CC1::AddCC1Args(const ArgList &Args, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2151 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 2152 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | e2fd664 | 2009-09-10 01:21:12 +0000 | [diff] [blame] | 2153 | |
| 2154 | CheckCodeGenerationOptions(D, Args); |
| 2155 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2156 | // Derived from cc1 spec. |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2157 | if (!Args.hasArg(options::OPT_mkernel) && !Args.hasArg(options::OPT_static) && |
| 2158 | !Args.hasArg(options::OPT_mdynamic_no_pic)) |
| 2159 | CmdArgs.push_back("-fPIC"); |
| 2160 | |
Daniel Dunbar | 2ba9157 | 2009-09-10 03:37:02 +0000 | [diff] [blame] | 2161 | if (getToolChain().getTriple().getArch() == llvm::Triple::arm || |
| 2162 | getToolChain().getTriple().getArch() == llvm::Triple::thumb) { |
| 2163 | if (!Args.hasArg(options::OPT_fbuiltin_strcat)) |
| 2164 | CmdArgs.push_back("-fno-builtin-strcat"); |
| 2165 | if (!Args.hasArg(options::OPT_fbuiltin_strcpy)) |
| 2166 | CmdArgs.push_back("-fno-builtin-strcpy"); |
| 2167 | } |
| 2168 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2169 | // gcc has some code here to deal with when no -mmacosx-version-min |
| 2170 | // and no -miphoneos-version-min is present, but this never happens |
| 2171 | // due to tool chain specific argument translation. |
| 2172 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2173 | if (Args.hasArg(options::OPT_g_Flag) && |
| 2174 | !Args.hasArg(options::OPT_fno_eliminate_unused_debug_symbols)) |
| 2175 | CmdArgs.push_back("-feliminate-unused-debug-symbols"); |
| 2176 | } |
| 2177 | |
| 2178 | void darwin::CC1::AddCC1OptionsArgs(const ArgList &Args, ArgStringList &CmdArgs, |
| 2179 | const InputInfoList &Inputs, |
| 2180 | const ArgStringList &OutputArgs) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 2181 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2182 | |
| 2183 | // Derived from cc1_options spec. |
| 2184 | if (Args.hasArg(options::OPT_fast) || |
| 2185 | Args.hasArg(options::OPT_fastf) || |
| 2186 | Args.hasArg(options::OPT_fastcp)) |
| 2187 | CmdArgs.push_back("-O3"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2188 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2189 | if (Arg *A = Args.getLastArg(options::OPT_pg)) |
| 2190 | if (Args.hasArg(options::OPT_fomit_frame_pointer)) |
| 2191 | D.Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 2192 | << A->getAsString(Args) << "-fomit-frame-pointer"; |
| 2193 | |
| 2194 | AddCC1Args(Args, CmdArgs); |
| 2195 | |
| 2196 | if (!Args.hasArg(options::OPT_Q)) |
| 2197 | CmdArgs.push_back("-quiet"); |
| 2198 | |
| 2199 | CmdArgs.push_back("-dumpbase"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 2200 | CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2201 | |
| 2202 | Args.AddAllArgs(CmdArgs, options::OPT_d_Group); |
| 2203 | |
| 2204 | Args.AddAllArgs(CmdArgs, options::OPT_m_Group); |
| 2205 | Args.AddAllArgs(CmdArgs, options::OPT_a_Group); |
| 2206 | |
| 2207 | // FIXME: The goal is to use the user provided -o if that is our |
| 2208 | // final output, otherwise to drive from the original input |
| 2209 | // name. Find a clean way to go about this. |
| 2210 | if ((Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) && |
| 2211 | Args.hasArg(options::OPT_o)) { |
| 2212 | Arg *OutputOpt = Args.getLastArg(options::OPT_o); |
| 2213 | CmdArgs.push_back("-auxbase-strip"); |
| 2214 | CmdArgs.push_back(OutputOpt->getValue(Args)); |
| 2215 | } else { |
| 2216 | CmdArgs.push_back("-auxbase"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 2217 | CmdArgs.push_back(darwin::CC1::getBaseInputStem(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | Args.AddAllArgs(CmdArgs, options::OPT_g_Group); |
| 2221 | |
| 2222 | Args.AddAllArgs(CmdArgs, options::OPT_O); |
| 2223 | // FIXME: -Wall is getting some special treatment. Investigate. |
| 2224 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group); |
| 2225 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2226 | Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2227 | options::OPT_trigraphs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 2228 | if (!Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { |
| 2229 | // Honor -std-default. |
| 2230 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, |
| 2231 | "-std=", /*Joined=*/true); |
| 2232 | } |
| 2233 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2234 | if (Args.hasArg(options::OPT_v)) |
| 2235 | CmdArgs.push_back("-version"); |
Daniel Dunbar | bbe8e3e | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 2236 | if (Args.hasArg(options::OPT_pg) && |
| 2237 | getToolChain().SupportsProfiling()) |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2238 | CmdArgs.push_back("-p"); |
| 2239 | Args.AddLastArg(CmdArgs, options::OPT_p); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2240 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2241 | // The driver treats -fsyntax-only specially. |
Daniel Dunbar | 2ba9157 | 2009-09-10 03:37:02 +0000 | [diff] [blame] | 2242 | if (getToolChain().getTriple().getArch() == llvm::Triple::arm || |
| 2243 | getToolChain().getTriple().getArch() == llvm::Triple::thumb) { |
| 2244 | // Removes -fbuiltin-str{cat,cpy}; these aren't recognized by cc1 but are |
| 2245 | // used to inhibit the default -fno-builtin-str{cat,cpy}. |
| 2246 | // |
| 2247 | // FIXME: Should we grow a better way to deal with "removing" args? |
Daniel Dunbar | cdd9686 | 2009-11-25 11:53:23 +0000 | [diff] [blame] | 2248 | for (arg_iterator it = Args.filtered_begin(options::OPT_f_Group, |
| 2249 | options::OPT_fsyntax_only), |
| 2250 | ie = Args.filtered_end(); it != ie; ++it) { |
Daniel Dunbar | 7e4953e | 2010-06-11 22:00:13 +0000 | [diff] [blame] | 2251 | if (!(*it)->getOption().matches(options::OPT_fbuiltin_strcat) && |
| 2252 | !(*it)->getOption().matches(options::OPT_fbuiltin_strcpy)) { |
| 2253 | (*it)->claim(); |
| 2254 | (*it)->render(Args, CmdArgs); |
Daniel Dunbar | 2ba9157 | 2009-09-10 03:37:02 +0000 | [diff] [blame] | 2255 | } |
| 2256 | } |
| 2257 | } else |
| 2258 | Args.AddAllArgs(CmdArgs, options::OPT_f_Group, options::OPT_fsyntax_only); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2259 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2260 | Args.AddAllArgs(CmdArgs, options::OPT_undef); |
| 2261 | if (Args.hasArg(options::OPT_Qn)) |
| 2262 | CmdArgs.push_back("-fno-ident"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2263 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2264 | // FIXME: This isn't correct. |
| 2265 | //Args.AddLastArg(CmdArgs, options::OPT__help) |
| 2266 | //Args.AddLastArg(CmdArgs, options::OPT__targetHelp) |
| 2267 | |
| 2268 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 2269 | |
| 2270 | // FIXME: Still don't get what is happening here. Investigate. |
| 2271 | Args.AddAllArgs(CmdArgs, options::OPT__param); |
| 2272 | |
| 2273 | if (Args.hasArg(options::OPT_fmudflap) || |
| 2274 | Args.hasArg(options::OPT_fmudflapth)) { |
| 2275 | CmdArgs.push_back("-fno-builtin"); |
| 2276 | CmdArgs.push_back("-fno-merge-constants"); |
| 2277 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2278 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2279 | if (Args.hasArg(options::OPT_coverage)) { |
| 2280 | CmdArgs.push_back("-fprofile-arcs"); |
| 2281 | CmdArgs.push_back("-ftest-coverage"); |
| 2282 | } |
| 2283 | |
| 2284 | if (types::isCXX(Inputs[0].getType())) |
| 2285 | CmdArgs.push_back("-D__private_extern__=extern"); |
| 2286 | } |
| 2287 | |
| 2288 | void darwin::CC1::AddCPPOptionsArgs(const ArgList &Args, ArgStringList &CmdArgs, |
| 2289 | const InputInfoList &Inputs, |
| 2290 | const ArgStringList &OutputArgs) const { |
| 2291 | // Derived from cpp_options |
| 2292 | AddCPPUniqueOptionsArgs(Args, CmdArgs, Inputs); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2293 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2294 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 2295 | |
| 2296 | AddCC1Args(Args, CmdArgs); |
| 2297 | |
| 2298 | // NOTE: The code below has some commonality with cpp_options, but |
| 2299 | // in classic gcc style ends up sending things in different |
| 2300 | // orders. This may be a good merge candidate once we drop pedantic |
| 2301 | // compatibility. |
| 2302 | |
| 2303 | Args.AddAllArgs(CmdArgs, options::OPT_m_Group); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2304 | Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2305 | options::OPT_trigraphs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 2306 | if (!Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { |
| 2307 | // Honor -std-default. |
| 2308 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, |
| 2309 | "-std=", /*Joined=*/true); |
| 2310 | } |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2311 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group); |
| 2312 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2313 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2314 | // The driver treats -fsyntax-only specially. |
| 2315 | Args.AddAllArgs(CmdArgs, options::OPT_f_Group, options::OPT_fsyntax_only); |
| 2316 | |
| 2317 | if (Args.hasArg(options::OPT_g_Group) && !Args.hasArg(options::OPT_g0) && |
| 2318 | !Args.hasArg(options::OPT_fno_working_directory)) |
| 2319 | CmdArgs.push_back("-fworking-directory"); |
| 2320 | |
| 2321 | Args.AddAllArgs(CmdArgs, options::OPT_O); |
| 2322 | Args.AddAllArgs(CmdArgs, options::OPT_undef); |
| 2323 | if (Args.hasArg(options::OPT_save_temps)) |
| 2324 | CmdArgs.push_back("-fpch-preprocess"); |
| 2325 | } |
| 2326 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2327 | void darwin::CC1::AddCPPUniqueOptionsArgs(const ArgList &Args, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2328 | ArgStringList &CmdArgs, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2329 | const InputInfoList &Inputs) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 2330 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2331 | |
Daniel Dunbar | 88a3d6c | 2009-09-10 01:21:05 +0000 | [diff] [blame] | 2332 | CheckPreprocessingOptions(D, Args); |
| 2333 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2334 | // Derived from cpp_unique_options. |
Daniel Dunbar | 88a3d6c | 2009-09-10 01:21:05 +0000 | [diff] [blame] | 2335 | // -{C,CC} only with -E is checked in CheckPreprocessingOptions(). |
| 2336 | Args.AddLastArg(CmdArgs, options::OPT_C); |
| 2337 | Args.AddLastArg(CmdArgs, options::OPT_CC); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2338 | if (!Args.hasArg(options::OPT_Q)) |
| 2339 | CmdArgs.push_back("-quiet"); |
| 2340 | Args.AddAllArgs(CmdArgs, options::OPT_nostdinc); |
Douglas Gregor | 4c2bcad | 2010-03-24 20:13:48 +0000 | [diff] [blame] | 2341 | Args.AddAllArgs(CmdArgs, options::OPT_nostdincxx); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2342 | Args.AddLastArg(CmdArgs, options::OPT_v); |
| 2343 | Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F); |
| 2344 | Args.AddLastArg(CmdArgs, options::OPT_P); |
| 2345 | |
| 2346 | // FIXME: Handle %I properly. |
| 2347 | if (getToolChain().getArchName() == "x86_64") { |
| 2348 | CmdArgs.push_back("-imultilib"); |
| 2349 | CmdArgs.push_back("x86_64"); |
| 2350 | } |
| 2351 | |
| 2352 | if (Args.hasArg(options::OPT_MD)) { |
| 2353 | CmdArgs.push_back("-MD"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 2354 | CmdArgs.push_back(darwin::CC1::getDependencyFileName(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | if (Args.hasArg(options::OPT_MMD)) { |
| 2358 | CmdArgs.push_back("-MMD"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 2359 | CmdArgs.push_back(darwin::CC1::getDependencyFileName(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | Args.AddLastArg(CmdArgs, options::OPT_M); |
| 2363 | Args.AddLastArg(CmdArgs, options::OPT_MM); |
| 2364 | Args.AddAllArgs(CmdArgs, options::OPT_MF); |
| 2365 | Args.AddLastArg(CmdArgs, options::OPT_MG); |
| 2366 | Args.AddLastArg(CmdArgs, options::OPT_MP); |
| 2367 | Args.AddAllArgs(CmdArgs, options::OPT_MQ); |
| 2368 | Args.AddAllArgs(CmdArgs, options::OPT_MT); |
| 2369 | if (!Args.hasArg(options::OPT_M) && !Args.hasArg(options::OPT_MM) && |
| 2370 | (Args.hasArg(options::OPT_MD) || Args.hasArg(options::OPT_MMD))) { |
| 2371 | if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) { |
| 2372 | CmdArgs.push_back("-MQ"); |
| 2373 | CmdArgs.push_back(OutputOpt->getValue(Args)); |
| 2374 | } |
| 2375 | } |
| 2376 | |
| 2377 | Args.AddLastArg(CmdArgs, options::OPT_remap); |
| 2378 | if (Args.hasArg(options::OPT_g3)) |
| 2379 | CmdArgs.push_back("-dD"); |
| 2380 | Args.AddLastArg(CmdArgs, options::OPT_H); |
| 2381 | |
| 2382 | AddCPPArgs(Args, CmdArgs); |
| 2383 | |
| 2384 | Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U, options::OPT_A); |
| 2385 | Args.AddAllArgs(CmdArgs, options::OPT_i_Group); |
| 2386 | |
| 2387 | for (InputInfoList::const_iterator |
| 2388 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 2389 | const InputInfo &II = *it; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2390 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 2391 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA, |
| 2395 | options::OPT_Xpreprocessor); |
| 2396 | |
| 2397 | if (Args.hasArg(options::OPT_fmudflap)) { |
| 2398 | CmdArgs.push_back("-D_MUDFLAP"); |
| 2399 | CmdArgs.push_back("-include"); |
| 2400 | CmdArgs.push_back("mf-runtime.h"); |
| 2401 | } |
| 2402 | |
| 2403 | if (Args.hasArg(options::OPT_fmudflapth)) { |
| 2404 | CmdArgs.push_back("-D_MUDFLAP"); |
| 2405 | CmdArgs.push_back("-D_MUDFLAPTH"); |
| 2406 | CmdArgs.push_back("-include"); |
| 2407 | CmdArgs.push_back("mf-runtime.h"); |
| 2408 | } |
| 2409 | } |
| 2410 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2411 | void darwin::CC1::AddCPPArgs(const ArgList &Args, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2412 | ArgStringList &CmdArgs) const { |
| 2413 | // Derived from cpp spec. |
| 2414 | |
| 2415 | if (Args.hasArg(options::OPT_static)) { |
| 2416 | // The gcc spec is broken here, it refers to dynamic but |
| 2417 | // that has been translated. Start by being bug compatible. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2418 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2419 | // if (!Args.hasArg(arglist.parser.dynamicOption)) |
| 2420 | CmdArgs.push_back("-D__STATIC__"); |
| 2421 | } else |
| 2422 | CmdArgs.push_back("-D__DYNAMIC__"); |
| 2423 | |
| 2424 | if (Args.hasArg(options::OPT_pthread)) |
| 2425 | CmdArgs.push_back("-D_REENTRANT"); |
| 2426 | } |
| 2427 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2428 | void darwin::Preprocess::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 2429 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2430 | const InputInfoList &Inputs, |
| 2431 | const ArgList &Args, |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2432 | const char *LinkingOutput) const { |
| 2433 | ArgStringList CmdArgs; |
| 2434 | |
| 2435 | assert(Inputs.size() == 1 && "Unexpected number of inputs!"); |
| 2436 | |
| 2437 | CmdArgs.push_back("-E"); |
| 2438 | |
| 2439 | if (Args.hasArg(options::OPT_traditional) || |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2440 | Args.hasArg(options::OPT_traditional_cpp)) |
| 2441 | CmdArgs.push_back("-traditional-cpp"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2442 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2443 | ArgStringList OutputArgs; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 2444 | assert(Output.isFilename() && "Unexpected CC1 output."); |
| 2445 | OutputArgs.push_back("-o"); |
| 2446 | OutputArgs.push_back(Output.getFilename()); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2447 | |
Joerg Sonnenberger | 9ade4ae | 2011-03-06 23:31:01 +0000 | [diff] [blame] | 2448 | if (Args.hasArg(options::OPT_E) || getToolChain().getDriver().CCCIsCPP) { |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 2449 | AddCPPOptionsArgs(Args, CmdArgs, Inputs, OutputArgs); |
| 2450 | } else { |
| 2451 | AddCPPOptionsArgs(Args, CmdArgs, Inputs, ArgStringList()); |
| 2452 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 2453 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2454 | |
Daniel Dunbar | 8a2073a | 2009-04-03 01:27:06 +0000 | [diff] [blame] | 2455 | Args.AddAllArgs(CmdArgs, options::OPT_d_Group); |
| 2456 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2457 | const char *CC1Name = getCC1Name(Inputs[0].getType()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2458 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 2459 | Args.MakeArgString(getToolChain().GetProgramPath(CC1Name)); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 2460 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | void darwin::Compile::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 2464 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2465 | const InputInfoList &Inputs, |
| 2466 | const ArgList &Args, |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2467 | const char *LinkingOutput) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 2468 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2469 | ArgStringList CmdArgs; |
| 2470 | |
| 2471 | assert(Inputs.size() == 1 && "Unexpected number of inputs!"); |
| 2472 | |
| 2473 | types::ID InputType = Inputs[0].getType(); |
| 2474 | const Arg *A; |
Eli Friedman | ceb5c5b | 2009-07-14 21:58:17 +0000 | [diff] [blame] | 2475 | if ((A = Args.getLastArg(options::OPT_traditional))) |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2476 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 2477 | << A->getAsString(Args) << "-E"; |
| 2478 | |
Daniel Dunbar | 6c6424b | 2010-06-07 23:28:45 +0000 | [diff] [blame] | 2479 | if (JA.getType() == types::TY_LLVM_IR || |
| 2480 | JA.getType() == types::TY_LTO_IR) |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2481 | CmdArgs.push_back("-emit-llvm"); |
Daniel Dunbar | 6c6424b | 2010-06-07 23:28:45 +0000 | [diff] [blame] | 2482 | else if (JA.getType() == types::TY_LLVM_BC || |
| 2483 | JA.getType() == types::TY_LTO_BC) |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2484 | CmdArgs.push_back("-emit-llvm-bc"); |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 2485 | else if (Output.getType() == types::TY_AST) |
| 2486 | D.Diag(clang::diag::err_drv_no_ast_support) |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 2487 | << getToolChain().getTripleString(); |
Daniel Dunbar | ae24a88 | 2010-02-11 17:33:45 +0000 | [diff] [blame] | 2488 | else if (JA.getType() != types::TY_PP_Asm && |
| 2489 | JA.getType() != types::TY_PCH) |
Daniel Dunbar | 6495250 | 2010-02-11 03:16:21 +0000 | [diff] [blame] | 2490 | D.Diag(clang::diag::err_drv_invalid_gcc_output_type) |
| 2491 | << getTypeName(JA.getType()); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2492 | |
| 2493 | ArgStringList OutputArgs; |
| 2494 | if (Output.getType() != types::TY_PCH) { |
| 2495 | OutputArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 2496 | if (Output.isNothing()) |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2497 | OutputArgs.push_back("/dev/null"); |
| 2498 | else |
| 2499 | OutputArgs.push_back(Output.getFilename()); |
| 2500 | } |
| 2501 | |
| 2502 | // There is no need for this level of compatibility, but it makes |
| 2503 | // diffing easier. |
| 2504 | bool OutputArgsEarly = (Args.hasArg(options::OPT_fsyntax_only) || |
| 2505 | Args.hasArg(options::OPT_S)); |
| 2506 | |
| 2507 | if (types::getPreprocessedType(InputType) != types::TY_INVALID) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 2508 | AddCPPUniqueOptionsArgs(Args, CmdArgs, Inputs); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2509 | if (OutputArgsEarly) { |
| 2510 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, OutputArgs); |
| 2511 | } else { |
| 2512 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, ArgStringList()); |
| 2513 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 2514 | } |
| 2515 | } else { |
| 2516 | CmdArgs.push_back("-fpreprocessed"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2517 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2518 | for (InputInfoList::const_iterator |
| 2519 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 2520 | const InputInfo &II = *it; |
| 2521 | |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 2522 | // Reject AST inputs. |
| 2523 | if (II.getType() == types::TY_AST) { |
| 2524 | D.Diag(clang::diag::err_drv_no_ast_support) |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 2525 | << getToolChain().getTripleString(); |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 2526 | return; |
| 2527 | } |
| 2528 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 2529 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | if (OutputArgsEarly) { |
| 2533 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, OutputArgs); |
| 2534 | } else { |
| 2535 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, ArgStringList()); |
| 2536 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 2537 | } |
| 2538 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2539 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2540 | if (Output.getType() == types::TY_PCH) { |
| 2541 | assert(Output.isFilename() && "Invalid PCH output."); |
| 2542 | |
| 2543 | CmdArgs.push_back("-o"); |
| 2544 | // NOTE: gcc uses a temp .s file for this, but there doesn't seem |
| 2545 | // to be a good reason. |
| 2546 | CmdArgs.push_back("/dev/null"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2547 | |
Daniel Dunbar | e6c9ae1 | 2009-11-21 02:31:29 +0000 | [diff] [blame] | 2548 | CmdArgs.push_back("--output-pch="); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2549 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2550 | } |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2551 | |
| 2552 | const char *CC1Name = getCC1Name(Inputs[0].getType()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2553 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 2554 | Args.MakeArgString(getToolChain().GetProgramPath(CC1Name)); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 2555 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 2556 | } |
| 2557 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 2558 | void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 2559 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2560 | const InputInfoList &Inputs, |
| 2561 | const ArgList &Args, |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 2562 | const char *LinkingOutput) const { |
| 2563 | ArgStringList CmdArgs; |
| 2564 | |
| 2565 | assert(Inputs.size() == 1 && "Unexpected number of inputs."); |
| 2566 | const InputInfo &Input = Inputs[0]; |
| 2567 | |
| 2568 | // Bit of a hack, this is only used for original inputs. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2569 | // |
Daniel Dunbar | 8e4fea6 | 2009-04-01 00:27:44 +0000 | [diff] [blame] | 2570 | // FIXME: This is broken for preprocessed .s inputs. |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 2571 | if (Input.isFilename() && |
Daniel Dunbar | 8e4fea6 | 2009-04-01 00:27:44 +0000 | [diff] [blame] | 2572 | strcmp(Input.getFilename(), Input.getBaseInput()) == 0) { |
| 2573 | if (Args.hasArg(options::OPT_gstabs)) |
| 2574 | CmdArgs.push_back("--gstabs"); |
| 2575 | else if (Args.hasArg(options::OPT_g_Group)) |
| 2576 | CmdArgs.push_back("--gdwarf2"); |
| 2577 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2578 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 2579 | // Derived from asm spec. |
Daniel Dunbar | cc6f803 | 2009-09-09 18:36:27 +0000 | [diff] [blame] | 2580 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 2581 | |
Daniel Dunbar | f5438e3 | 2010-07-22 01:47:22 +0000 | [diff] [blame] | 2582 | // Use -force_cpusubtype_ALL on x86 by default. |
| 2583 | if (getToolChain().getTriple().getArch() == llvm::Triple::x86 || |
| 2584 | getToolChain().getTriple().getArch() == llvm::Triple::x86_64 || |
Daniel Dunbar | cc6f803 | 2009-09-09 18:36:27 +0000 | [diff] [blame] | 2585 | Args.hasArg(options::OPT_force__cpusubtype__ALL)) |
| 2586 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
| 2587 | |
Daniel Dunbar | 0e2679d | 2009-08-24 22:26:16 +0000 | [diff] [blame] | 2588 | if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64 && |
| 2589 | (Args.hasArg(options::OPT_mkernel) || |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 2590 | Args.hasArg(options::OPT_static) || |
Daniel Dunbar | 0e2679d | 2009-08-24 22:26:16 +0000 | [diff] [blame] | 2591 | Args.hasArg(options::OPT_fapple_kext))) |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2592 | CmdArgs.push_back("-static"); |
| 2593 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 2594 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 2595 | options::OPT_Xassembler); |
| 2596 | |
| 2597 | assert(Output.isFilename() && "Unexpected lipo output."); |
| 2598 | CmdArgs.push_back("-o"); |
| 2599 | CmdArgs.push_back(Output.getFilename()); |
| 2600 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 2601 | assert(Input.isFilename() && "Invalid input."); |
| 2602 | CmdArgs.push_back(Input.getFilename()); |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 2603 | |
| 2604 | // asm_final spec is empty. |
| 2605 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2606 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 2607 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 2608 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 2609 | } |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 2610 | |
Daniel Dunbar | fbefe6b | 2009-09-09 18:36:20 +0000 | [diff] [blame] | 2611 | void darwin::DarwinTool::AddDarwinArch(const ArgList &Args, |
| 2612 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 2613 | llvm::StringRef ArchName = getDarwinToolChain().getDarwinArchName(Args); |
| 2614 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2615 | // Derived from darwin_arch spec. |
| 2616 | CmdArgs.push_back("-arch"); |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 2617 | CmdArgs.push_back(Args.MakeArgString(ArchName)); |
Daniel Dunbar | 78dbd58 | 2009-09-04 18:35:31 +0000 | [diff] [blame] | 2618 | |
Daniel Dunbar | eeff406 | 2010-01-22 02:04:58 +0000 | [diff] [blame] | 2619 | // FIXME: Is this needed anymore? |
| 2620 | if (ArchName == "arm") |
Daniel Dunbar | 78dbd58 | 2009-09-04 18:35:31 +0000 | [diff] [blame] | 2621 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
Daniel Dunbar | 748de8e | 2010-09-09 21:51:05 +0000 | [diff] [blame] | 2624 | void darwin::Link::AddLinkArgs(Compilation &C, |
| 2625 | const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2626 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 2627 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2628 | |
Daniel Dunbar | b18dc5b | 2010-08-11 23:07:50 +0000 | [diff] [blame] | 2629 | unsigned Version[3] = { 0, 0, 0 }; |
| 2630 | if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) { |
| 2631 | bool HadExtra; |
| 2632 | if (!Driver::GetReleaseVersion(A->getValue(Args), Version[0], |
| 2633 | Version[1], Version[2], HadExtra) || |
| 2634 | HadExtra) |
| 2635 | D.Diag(clang::diag::err_drv_invalid_version_number) |
| 2636 | << A->getAsString(Args); |
| 2637 | } |
| 2638 | |
| 2639 | // Newer linkers support -demangle, pass it if supported and not disabled by |
| 2640 | // the user. |
Daniel Dunbar | a30d6cd | 2010-11-19 17:51:40 +0000 | [diff] [blame] | 2641 | // |
| 2642 | // FIXME: We temporarily avoid passing -demangle to any iOS linker, because |
| 2643 | // unfortunately we can't be guaranteed that the linker version used there |
| 2644 | // will match the linker version detected at configure time. We need the |
| 2645 | // universal driver. |
| 2646 | if (Version[0] >= 100 && !Args.hasArg(options::OPT_Z_Xlinker__no_demangle) && |
| 2647 | !getDarwinToolChain().isTargetIPhoneOS()) { |
Daniel Dunbar | bcf1da8 | 2010-09-07 17:07:49 +0000 | [diff] [blame] | 2648 | // Don't pass -demangle to ld_classic. |
| 2649 | // |
| 2650 | // FIXME: This is a temporary workaround, ld should be handling this. |
| 2651 | bool UsesLdClassic = (getToolChain().getArch() == llvm::Triple::x86 && |
| 2652 | Args.hasArg(options::OPT_static)); |
Daniel Dunbar | 9ced704 | 2010-09-07 17:50:41 +0000 | [diff] [blame] | 2653 | if (getToolChain().getArch() == llvm::Triple::x86) { |
| 2654 | for (arg_iterator it = Args.filtered_begin(options::OPT_Xlinker, |
| 2655 | options::OPT_Wl_COMMA), |
| 2656 | ie = Args.filtered_end(); it != ie; ++it) { |
| 2657 | const Arg *A = *it; |
| 2658 | for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) |
| 2659 | if (llvm::StringRef(A->getValue(Args, i)) == "-kext") |
| 2660 | UsesLdClassic = true; |
| 2661 | } |
| 2662 | } |
Daniel Dunbar | bcf1da8 | 2010-09-07 17:07:49 +0000 | [diff] [blame] | 2663 | if (!UsesLdClassic) |
| 2664 | CmdArgs.push_back("-demangle"); |
Daniel Dunbar | b18dc5b | 2010-08-11 23:07:50 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2667 | // Derived from the "link" spec. |
| 2668 | Args.AddAllArgs(CmdArgs, options::OPT_static); |
| 2669 | if (!Args.hasArg(options::OPT_static)) |
| 2670 | CmdArgs.push_back("-dynamic"); |
| 2671 | if (Args.hasArg(options::OPT_fgnu_runtime)) { |
| 2672 | // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu |
| 2673 | // here. How do we wish to handle such things? |
| 2674 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2675 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2676 | if (!Args.hasArg(options::OPT_dynamiclib)) { |
Daniel Dunbar | a6d3849 | 2010-01-22 02:04:52 +0000 | [diff] [blame] | 2677 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | a6d3849 | 2010-01-22 02:04:52 +0000 | [diff] [blame] | 2678 | // FIXME: Why do this only on this path? |
Daniel Dunbar | 8917dd4 | 2010-01-22 03:37:33 +0000 | [diff] [blame] | 2679 | Args.AddLastArg(CmdArgs, options::OPT_force__cpusubtype__ALL); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2680 | |
| 2681 | Args.AddLastArg(CmdArgs, options::OPT_bundle); |
| 2682 | Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader); |
| 2683 | Args.AddAllArgs(CmdArgs, options::OPT_client__name); |
| 2684 | |
| 2685 | Arg *A; |
| 2686 | if ((A = Args.getLastArg(options::OPT_compatibility__version)) || |
| 2687 | (A = Args.getLastArg(options::OPT_current__version)) || |
| 2688 | (A = Args.getLastArg(options::OPT_install__name))) |
| 2689 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 2690 | << A->getAsString(Args) << "-dynamiclib"; |
| 2691 | |
| 2692 | Args.AddLastArg(CmdArgs, options::OPT_force__flat__namespace); |
| 2693 | Args.AddLastArg(CmdArgs, options::OPT_keep__private__externs); |
| 2694 | Args.AddLastArg(CmdArgs, options::OPT_private__bundle); |
| 2695 | } else { |
| 2696 | CmdArgs.push_back("-dylib"); |
| 2697 | |
| 2698 | Arg *A; |
| 2699 | if ((A = Args.getLastArg(options::OPT_bundle)) || |
| 2700 | (A = Args.getLastArg(options::OPT_bundle__loader)) || |
| 2701 | (A = Args.getLastArg(options::OPT_client__name)) || |
| 2702 | (A = Args.getLastArg(options::OPT_force__flat__namespace)) || |
| 2703 | (A = Args.getLastArg(options::OPT_keep__private__externs)) || |
| 2704 | (A = Args.getLastArg(options::OPT_private__bundle))) |
| 2705 | D.Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 2706 | << A->getAsString(Args) << "-dynamiclib"; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2707 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2708 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_compatibility__version, |
| 2709 | "-dylib_compatibility_version"); |
| 2710 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version, |
| 2711 | "-dylib_current_version"); |
| 2712 | |
Daniel Dunbar | a6d3849 | 2010-01-22 02:04:52 +0000 | [diff] [blame] | 2713 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2714 | |
| 2715 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name, |
| 2716 | "-dylib_install_name"); |
| 2717 | } |
| 2718 | |
| 2719 | Args.AddLastArg(CmdArgs, options::OPT_all__load); |
| 2720 | Args.AddAllArgs(CmdArgs, options::OPT_allowable__client); |
| 2721 | Args.AddLastArg(CmdArgs, options::OPT_bind__at__load); |
Daniel Dunbar | 251ca6c | 2010-01-27 00:56:37 +0000 | [diff] [blame] | 2722 | if (getDarwinToolChain().isTargetIPhoneOS()) |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 2723 | Args.AddLastArg(CmdArgs, options::OPT_arch__errors__fatal); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2724 | Args.AddLastArg(CmdArgs, options::OPT_dead__strip); |
| 2725 | Args.AddLastArg(CmdArgs, options::OPT_no__dead__strip__inits__and__terms); |
| 2726 | Args.AddAllArgs(CmdArgs, options::OPT_dylib__file); |
| 2727 | Args.AddLastArg(CmdArgs, options::OPT_dynamic); |
| 2728 | Args.AddAllArgs(CmdArgs, options::OPT_exported__symbols__list); |
| 2729 | Args.AddLastArg(CmdArgs, options::OPT_flat__namespace); |
| 2730 | Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names); |
| 2731 | Args.AddAllArgs(CmdArgs, options::OPT_image__base); |
| 2732 | Args.AddAllArgs(CmdArgs, options::OPT_init); |
| 2733 | |
Daniel Dunbar | 314cba0 | 2010-01-26 03:56:40 +0000 | [diff] [blame] | 2734 | // Adding all arguments doesn't make sense here but this is what gcc does. One |
| 2735 | // of this should always be present thanks to argument translation. |
| 2736 | assert((Args.hasArg(options::OPT_mmacosx_version_min_EQ) || |
| 2737 | Args.hasArg(options::OPT_miphoneos_version_min_EQ)) && |
| 2738 | "Missing version argument (lost in translation)?"); |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 2739 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_mmacosx_version_min_EQ, |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 2740 | "-macosx_version_min"); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2741 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_miphoneos_version_min_EQ, |
| 2742 | "-iphoneos_version_min"); |
| 2743 | Args.AddLastArg(CmdArgs, options::OPT_nomultidefs); |
| 2744 | Args.AddLastArg(CmdArgs, options::OPT_multi__module); |
| 2745 | Args.AddLastArg(CmdArgs, options::OPT_single__module); |
| 2746 | Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined); |
| 2747 | Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2748 | |
Daniel Dunbar | 47e879d | 2010-07-13 23:31:40 +0000 | [diff] [blame] | 2749 | if (const Arg *A = Args.getLastArg(options::OPT_fpie, options::OPT_fPIE, |
| 2750 | options::OPT_fno_pie, |
| 2751 | options::OPT_fno_PIE)) { |
| 2752 | if (A->getOption().matches(options::OPT_fpie) || |
| 2753 | A->getOption().matches(options::OPT_fPIE)) |
| 2754 | CmdArgs.push_back("-pie"); |
| 2755 | else |
| 2756 | CmdArgs.push_back("-no_pie"); |
| 2757 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2758 | |
| 2759 | Args.AddLastArg(CmdArgs, options::OPT_prebind); |
| 2760 | Args.AddLastArg(CmdArgs, options::OPT_noprebind); |
| 2761 | Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding); |
| 2762 | Args.AddLastArg(CmdArgs, options::OPT_prebind__all__twolevel__modules); |
| 2763 | Args.AddLastArg(CmdArgs, options::OPT_read__only__relocs); |
| 2764 | Args.AddAllArgs(CmdArgs, options::OPT_sectcreate); |
| 2765 | Args.AddAllArgs(CmdArgs, options::OPT_sectorder); |
| 2766 | Args.AddAllArgs(CmdArgs, options::OPT_seg1addr); |
| 2767 | Args.AddAllArgs(CmdArgs, options::OPT_segprot); |
| 2768 | Args.AddAllArgs(CmdArgs, options::OPT_segaddr); |
| 2769 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__only__addr); |
| 2770 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__write__addr); |
| 2771 | Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table); |
| 2772 | Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table__filename); |
| 2773 | Args.AddAllArgs(CmdArgs, options::OPT_sub__library); |
| 2774 | Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella); |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 2775 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2776 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_isysroot, "-syslibroot"); |
Daniel Dunbar | 251ca6c | 2010-01-27 00:56:37 +0000 | [diff] [blame] | 2777 | if (getDarwinToolChain().isTargetIPhoneOS()) { |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 2778 | if (!Args.hasArg(options::OPT_isysroot)) { |
| 2779 | CmdArgs.push_back("-syslibroot"); |
| 2780 | CmdArgs.push_back("/Developer/SDKs/Extra"); |
| 2781 | } |
| 2782 | } |
| 2783 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2784 | Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace); |
| 2785 | Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace__hints); |
| 2786 | Args.AddAllArgs(CmdArgs, options::OPT_umbrella); |
| 2787 | Args.AddAllArgs(CmdArgs, options::OPT_undefined); |
| 2788 | Args.AddAllArgs(CmdArgs, options::OPT_unexported__symbols__list); |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 2789 | Args.AddAllArgs(CmdArgs, options::OPT_weak__reference__mismatches); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2790 | Args.AddLastArg(CmdArgs, options::OPT_X_Flag); |
| 2791 | Args.AddAllArgs(CmdArgs, options::OPT_y); |
| 2792 | Args.AddLastArg(CmdArgs, options::OPT_w); |
| 2793 | Args.AddAllArgs(CmdArgs, options::OPT_pagezero__size); |
| 2794 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__); |
| 2795 | Args.AddLastArg(CmdArgs, options::OPT_seglinkedit); |
| 2796 | Args.AddLastArg(CmdArgs, options::OPT_noseglinkedit); |
| 2797 | Args.AddAllArgs(CmdArgs, options::OPT_sectalign); |
| 2798 | Args.AddAllArgs(CmdArgs, options::OPT_sectobjectsymbols); |
| 2799 | Args.AddAllArgs(CmdArgs, options::OPT_segcreate); |
| 2800 | Args.AddLastArg(CmdArgs, options::OPT_whyload); |
| 2801 | Args.AddLastArg(CmdArgs, options::OPT_whatsloaded); |
| 2802 | Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name); |
| 2803 | Args.AddLastArg(CmdArgs, options::OPT_dylinker); |
| 2804 | Args.AddLastArg(CmdArgs, options::OPT_Mach); |
| 2805 | } |
| 2806 | |
| 2807 | void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 2808 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2809 | const InputInfoList &Inputs, |
| 2810 | const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2811 | const char *LinkingOutput) const { |
| 2812 | assert(Output.getType() == types::TY_Image && "Invalid linker output type."); |
Daniel Dunbar | e0be8b1 | 2009-09-08 16:39:16 +0000 | [diff] [blame] | 2813 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2814 | // The logic here is derived from gcc's behavior; most of which |
| 2815 | // comes from specs (starting with link_command). Consult gcc for |
| 2816 | // more information. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2817 | ArgStringList CmdArgs; |
| 2818 | |
| 2819 | // I'm not sure why this particular decomposition exists in gcc, but |
| 2820 | // we follow suite for ease of comparison. |
Daniel Dunbar | 748de8e | 2010-09-09 21:51:05 +0000 | [diff] [blame] | 2821 | AddLinkArgs(C, Args, CmdArgs); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2822 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2823 | Args.AddAllArgs(CmdArgs, options::OPT_d_Flag); |
| 2824 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 2825 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 2826 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 2827 | Args.AddAllArgs(CmdArgs, options::OPT_u_Group); |
| 2828 | Args.AddAllArgs(CmdArgs, options::OPT_A); |
| 2829 | Args.AddLastArg(CmdArgs, options::OPT_e); |
| 2830 | Args.AddAllArgs(CmdArgs, options::OPT_m_Separate); |
| 2831 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
| 2832 | |
Daniel Dunbar | 270073c | 2010-10-18 22:08:36 +0000 | [diff] [blame] | 2833 | // Forward -ObjC when either -ObjC or -ObjC++ is used, to force loading |
| 2834 | // members of static archive libraries which implement Objective-C classes or |
| 2835 | // categories. |
| 2836 | if (Args.hasArg(options::OPT_ObjC) || Args.hasArg(options::OPT_ObjCXX)) |
| 2837 | CmdArgs.push_back("-ObjC"); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2838 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2839 | CmdArgs.push_back("-o"); |
| 2840 | CmdArgs.push_back(Output.getFilename()); |
| 2841 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2842 | if (!Args.hasArg(options::OPT_A) && |
| 2843 | !Args.hasArg(options::OPT_nostdlib) && |
| 2844 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 2845 | // Derived from startfile spec. |
| 2846 | if (Args.hasArg(options::OPT_dynamiclib)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2847 | // Derived from darwin_dylib1 spec. |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 2848 | if (getDarwinToolChain().isTargetIPhoneOS()) { |
| 2849 | if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1)) |
| 2850 | CmdArgs.push_back("-ldylib1.o"); |
| 2851 | } else { |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 2852 | if (getDarwinToolChain().isMacosxVersionLT(10, 5)) |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 2853 | CmdArgs.push_back("-ldylib1.o"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 2854 | else if (getDarwinToolChain().isMacosxVersionLT(10, 6)) |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 2855 | CmdArgs.push_back("-ldylib1.10.5.o"); |
| 2856 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2857 | } else { |
| 2858 | if (Args.hasArg(options::OPT_bundle)) { |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 2859 | if (!Args.hasArg(options::OPT_static)) { |
| 2860 | // Derived from darwin_bundle1 spec. |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 2861 | if (getDarwinToolChain().isTargetIPhoneOS()) { |
| 2862 | if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1)) |
| 2863 | CmdArgs.push_back("-lbundle1.o"); |
| 2864 | } else { |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 2865 | if (getDarwinToolChain().isMacosxVersionLT(10, 6)) |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 2866 | CmdArgs.push_back("-lbundle1.o"); |
| 2867 | } |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 2868 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2869 | } else { |
Daniel Dunbar | bbe8e3e | 2011-03-01 18:49:30 +0000 | [diff] [blame] | 2870 | if (Args.hasArg(options::OPT_pg) && |
| 2871 | getToolChain().SupportsProfiling()) { |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2872 | if (Args.hasArg(options::OPT_static) || |
| 2873 | Args.hasArg(options::OPT_object) || |
| 2874 | Args.hasArg(options::OPT_preload)) { |
| 2875 | CmdArgs.push_back("-lgcrt0.o"); |
| 2876 | } else { |
| 2877 | CmdArgs.push_back("-lgcrt1.o"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2878 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2879 | // darwin_crt2 spec is empty. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2880 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2881 | } else { |
| 2882 | if (Args.hasArg(options::OPT_static) || |
| 2883 | Args.hasArg(options::OPT_object) || |
| 2884 | Args.hasArg(options::OPT_preload)) { |
| 2885 | CmdArgs.push_back("-lcrt0.o"); |
| 2886 | } else { |
| 2887 | // Derived from darwin_crt1 spec. |
Daniel Dunbar | 251ca6c | 2010-01-27 00:56:37 +0000 | [diff] [blame] | 2888 | if (getDarwinToolChain().isTargetIPhoneOS()) { |
Daniel Dunbar | cacb0f0 | 2010-01-27 00:56:56 +0000 | [diff] [blame] | 2889 | if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1)) |
| 2890 | CmdArgs.push_back("-lcrt1.o"); |
| 2891 | else |
| 2892 | CmdArgs.push_back("-lcrt1.3.1.o"); |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 2893 | } else { |
| 2894 | if (getDarwinToolChain().isMacosxVersionLT(10, 5)) |
| 2895 | CmdArgs.push_back("-lcrt1.o"); |
| 2896 | else if (getDarwinToolChain().isMacosxVersionLT(10, 6)) |
| 2897 | CmdArgs.push_back("-lcrt1.10.5.o"); |
| 2898 | else |
| 2899 | CmdArgs.push_back("-lcrt1.10.6.o"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2900 | |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 2901 | // darwin_crt2 spec is empty. |
| 2902 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2903 | } |
| 2904 | } |
| 2905 | } |
| 2906 | } |
| 2907 | |
Daniel Dunbar | ce3fdf2 | 2010-01-27 00:57:03 +0000 | [diff] [blame] | 2908 | if (!getDarwinToolChain().isTargetIPhoneOS() && |
| 2909 | Args.hasArg(options::OPT_shared_libgcc) && |
| 2910 | getDarwinToolChain().isMacosxVersionLT(10, 5)) { |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 2911 | const char *Str = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 2912 | Args.MakeArgString(getToolChain().GetFilePath("crt3.o")); |
Daniel Dunbar | 8813764 | 2009-09-09 22:32:48 +0000 | [diff] [blame] | 2913 | CmdArgs.push_back(Str); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2918 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2919 | if (Args.hasArg(options::OPT_fopenmp)) |
| 2920 | // This is more complicated in gcc... |
| 2921 | CmdArgs.push_back("-lgomp"); |
| 2922 | |
Daniel Dunbar | 6b200b2 | 2009-09-18 08:14:36 +0000 | [diff] [blame] | 2923 | getDarwinToolChain().AddLinkSearchPathArgs(Args, CmdArgs); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2924 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 2925 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2926 | |
| 2927 | if (LinkingOutput) { |
| 2928 | CmdArgs.push_back("-arch_multiple"); |
| 2929 | CmdArgs.push_back("-final_output"); |
| 2930 | CmdArgs.push_back(LinkingOutput); |
| 2931 | } |
| 2932 | |
| 2933 | if (Args.hasArg(options::OPT_fprofile_arcs) || |
| 2934 | Args.hasArg(options::OPT_fprofile_generate) || |
| 2935 | Args.hasArg(options::OPT_fcreate_profile) || |
| 2936 | Args.hasArg(options::OPT_coverage)) |
| 2937 | CmdArgs.push_back("-lgcov"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2938 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2939 | if (Args.hasArg(options::OPT_fnested_functions)) |
| 2940 | CmdArgs.push_back("-allow_stack_execute"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2941 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2942 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 2943 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 2944 | if (getToolChain().getDriver().CCCIsCXX) |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 2945 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Daniel Dunbar | edfa02b | 2009-04-08 06:06:21 +0000 | [diff] [blame] | 2946 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2947 | // link_ssp spec is empty. |
| 2948 | |
Daniel Dunbar | 6cd4154 | 2009-09-18 08:15:03 +0000 | [diff] [blame] | 2949 | // Let the tool chain choose which runtime library to link. |
| 2950 | getDarwinToolChain().AddLinkRuntimeLibArgs(Args, CmdArgs); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2951 | } |
| 2952 | |
| 2953 | if (!Args.hasArg(options::OPT_A) && |
| 2954 | !Args.hasArg(options::OPT_nostdlib) && |
| 2955 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 2956 | // endfile_spec is empty. |
| 2957 | } |
| 2958 | |
| 2959 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 2960 | Args.AddAllArgs(CmdArgs, options::OPT_F); |
| 2961 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2962 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 2963 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 2964 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 2965 | } |
| 2966 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 2967 | void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 2968 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2969 | const InputInfoList &Inputs, |
| 2970 | const ArgList &Args, |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 2971 | const char *LinkingOutput) const { |
| 2972 | ArgStringList CmdArgs; |
| 2973 | |
| 2974 | CmdArgs.push_back("-create"); |
| 2975 | assert(Output.isFilename() && "Unexpected lipo output."); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 2976 | |
| 2977 | CmdArgs.push_back("-output"); |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 2978 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 2979 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 2980 | for (InputInfoList::const_iterator |
| 2981 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 2982 | const InputInfo &II = *it; |
| 2983 | assert(II.isFilename() && "Unexpected lipo input."); |
| 2984 | CmdArgs.push_back(II.getFilename()); |
| 2985 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2986 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 2987 | Args.MakeArgString(getToolChain().GetProgramPath("lipo")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 2988 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 2989 | } |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 2990 | |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 2991 | void darwin::Dsymutil::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 2992 | const InputInfo &Output, |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 2993 | const InputInfoList &Inputs, |
| 2994 | const ArgList &Args, |
| 2995 | const char *LinkingOutput) const { |
| 2996 | ArgStringList CmdArgs; |
| 2997 | |
| 2998 | assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); |
| 2999 | const InputInfo &Input = Inputs[0]; |
| 3000 | assert(Input.isFilename() && "Unexpected dsymutil input."); |
| 3001 | CmdArgs.push_back(Input.getFilename()); |
| 3002 | |
| 3003 | CmdArgs.push_back("-o"); |
| 3004 | CmdArgs.push_back(Output.getFilename()); |
| 3005 | |
| 3006 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3007 | Args.MakeArgString(getToolChain().GetProgramPath("dsymutil")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3008 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 6e0f254 | 2010-06-04 18:28:36 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3011 | void auroraux::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3012 | const InputInfo &Output, |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 3013 | const InputInfoList &Inputs, |
| 3014 | const ArgList &Args, |
| 3015 | const char *LinkingOutput) const { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3016 | ArgStringList CmdArgs; |
| 3017 | |
| 3018 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3019 | options::OPT_Xassembler); |
| 3020 | |
| 3021 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3022 | CmdArgs.push_back(Output.getFilename()); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3023 | |
| 3024 | for (InputInfoList::const_iterator |
| 3025 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3026 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3027 | CmdArgs.push_back(II.getFilename()); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3031 | Args.MakeArgString(getToolChain().GetProgramPath("gas")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3032 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | void auroraux::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3036 | const InputInfo &Output, |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 3037 | const InputInfoList &Inputs, |
| 3038 | const ArgList &Args, |
| 3039 | const char *LinkingOutput) const { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3040 | ArgStringList CmdArgs; |
| 3041 | |
| 3042 | if ((!Args.hasArg(options::OPT_nostdlib)) && |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 3043 | (!Args.hasArg(options::OPT_shared))) { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3044 | CmdArgs.push_back("-e"); |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 3045 | CmdArgs.push_back("_start"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3046 | } |
| 3047 | |
| 3048 | if (Args.hasArg(options::OPT_static)) { |
| 3049 | CmdArgs.push_back("-Bstatic"); |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 3050 | CmdArgs.push_back("-dn"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3051 | } else { |
Edward O'Callaghan | 7adf949 | 2009-10-15 07:44:07 +0000 | [diff] [blame] | 3052 | // CmdArgs.push_back("--eh-frame-hdr"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3053 | CmdArgs.push_back("-Bdynamic"); |
| 3054 | if (Args.hasArg(options::OPT_shared)) { |
| 3055 | CmdArgs.push_back("-shared"); |
| 3056 | } else { |
Edward O'Callaghan | 3cecc19 | 2009-10-16 19:44:18 +0000 | [diff] [blame] | 3057 | CmdArgs.push_back("--dynamic-linker"); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3058 | CmdArgs.push_back("/lib/ld.so.1"); // 64Bit Path /lib/amd64/ld.so.1 |
| 3059 | } |
| 3060 | } |
| 3061 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3062 | if (Output.isFilename()) { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3063 | CmdArgs.push_back("-o"); |
| 3064 | CmdArgs.push_back(Output.getFilename()); |
| 3065 | } else { |
| 3066 | assert(Output.isNothing() && "Invalid output."); |
| 3067 | } |
| 3068 | |
| 3069 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3070 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 3071 | if (!Args.hasArg(options::OPT_shared)) { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3072 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3073 | getToolChain().GetFilePath("crt1.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3074 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3075 | getToolChain().GetFilePath("crti.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3076 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3077 | getToolChain().GetFilePath("crtbegin.o"))); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3078 | } else { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3079 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3080 | getToolChain().GetFilePath("crti.o"))); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3081 | } |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3082 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3083 | getToolChain().GetFilePath("crtn.o"))); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3084 | } |
| 3085 | |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 3086 | CmdArgs.push_back(Args.MakeArgString("-L/opt/gcc4/lib/gcc/" |
| 3087 | + getToolChain().getTripleString() |
Daniel Dunbar | f7fb31f | 2009-10-29 02:24:37 +0000 | [diff] [blame] | 3088 | + "/4.2.4")); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3089 | |
| 3090 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 3091 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 3092 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 3093 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 3094 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3095 | |
| 3096 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3097 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 3098 | // FIXME: For some reason GCC passes -lgcc before adding |
| 3099 | // the default system libraries. Just mimic this for now. |
| 3100 | CmdArgs.push_back("-lgcc"); |
| 3101 | |
| 3102 | if (Args.hasArg(options::OPT_pthread)) |
| 3103 | CmdArgs.push_back("-pthread"); |
| 3104 | if (!Args.hasArg(options::OPT_shared)) |
| 3105 | CmdArgs.push_back("-lc"); |
| 3106 | CmdArgs.push_back("-lgcc"); |
| 3107 | } |
| 3108 | |
| 3109 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3110 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 3111 | if (!Args.hasArg(options::OPT_shared)) |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3112 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3113 | getToolChain().GetFilePath("crtend.o"))); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3117 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3118 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 3119 | } |
| 3120 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3121 | void openbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3122 | const InputInfo &Output, |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3123 | const InputInfoList &Inputs, |
| 3124 | const ArgList &Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3125 | const char *LinkingOutput) const { |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3126 | ArgStringList CmdArgs; |
| 3127 | |
| 3128 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3129 | options::OPT_Xassembler); |
| 3130 | |
| 3131 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3132 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3133 | |
| 3134 | for (InputInfoList::const_iterator |
| 3135 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3136 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3137 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3141 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3142 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3143 | } |
| 3144 | |
| 3145 | void openbsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3146 | const InputInfo &Output, |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3147 | const InputInfoList &Inputs, |
| 3148 | const ArgList &Args, |
| 3149 | const char *LinkingOutput) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3150 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3151 | ArgStringList CmdArgs; |
| 3152 | |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 3153 | if ((!Args.hasArg(options::OPT_nostdlib)) && |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 3154 | (!Args.hasArg(options::OPT_shared))) { |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 3155 | CmdArgs.push_back("-e"); |
| 3156 | CmdArgs.push_back("__start"); |
| 3157 | } |
| 3158 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3159 | if (Args.hasArg(options::OPT_static)) { |
| 3160 | CmdArgs.push_back("-Bstatic"); |
| 3161 | } else { |
Rafael Espindola | 65ba55d | 2010-11-11 02:17:51 +0000 | [diff] [blame] | 3162 | if (Args.hasArg(options::OPT_rdynamic)) |
| 3163 | CmdArgs.push_back("-export-dynamic"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3164 | CmdArgs.push_back("--eh-frame-hdr"); |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 3165 | CmdArgs.push_back("-Bdynamic"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3166 | if (Args.hasArg(options::OPT_shared)) { |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 3167 | CmdArgs.push_back("-shared"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3168 | } else { |
| 3169 | CmdArgs.push_back("-dynamic-linker"); |
| 3170 | CmdArgs.push_back("/usr/libexec/ld.so"); |
| 3171 | } |
| 3172 | } |
| 3173 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3174 | if (Output.isFilename()) { |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3175 | CmdArgs.push_back("-o"); |
| 3176 | CmdArgs.push_back(Output.getFilename()); |
| 3177 | } else { |
| 3178 | assert(Output.isNothing() && "Invalid output."); |
| 3179 | } |
| 3180 | |
| 3181 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3182 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 3183 | if (!Args.hasArg(options::OPT_shared)) { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3184 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3185 | getToolChain().GetFilePath("crt0.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3186 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3187 | getToolChain().GetFilePath("crtbegin.o"))); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3188 | } else { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3189 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3190 | getToolChain().GetFilePath("crtbeginS.o"))); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3191 | } |
| 3192 | } |
| 3193 | |
Edward O'Callaghan | e7e1820 | 2009-10-28 15:13:08 +0000 | [diff] [blame] | 3194 | std::string Triple = getToolChain().getTripleString(); |
| 3195 | if (Triple.substr(0, 6) == "x86_64") |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 3196 | Triple.replace(0, 6, "amd64"); |
Daniel Dunbar | f7fb31f | 2009-10-29 02:24:37 +0000 | [diff] [blame] | 3197 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc-lib/" + Triple + |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 3198 | "/4.2.1")); |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 3199 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3200 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 3201 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 3202 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 3203 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 3204 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3205 | |
| 3206 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3207 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 3208 | if (D.CCCIsCXX) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 3209 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Daniel Dunbar | 95c0457 | 2010-08-01 23:13:54 +0000 | [diff] [blame] | 3210 | CmdArgs.push_back("-lm"); |
| 3211 | } |
| 3212 | |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 3213 | // FIXME: For some reason GCC passes -lgcc before adding |
| 3214 | // the default system libraries. Just mimic this for now. |
| 3215 | CmdArgs.push_back("-lgcc"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3216 | |
| 3217 | if (Args.hasArg(options::OPT_pthread)) |
Chris Lattner | a2e4021 | 2011-02-21 18:36:51 +0000 | [diff] [blame] | 3218 | CmdArgs.push_back("-lpthread"); |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 3219 | if (!Args.hasArg(options::OPT_shared)) |
| 3220 | CmdArgs.push_back("-lc"); |
| 3221 | CmdArgs.push_back("-lgcc"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3225 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 3226 | if (!Args.hasArg(options::OPT_shared)) |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3227 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3228 | getToolChain().GetFilePath("crtend.o"))); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3229 | else |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3230 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3231 | getToolChain().GetFilePath("crtendS.o"))); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3235 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3236 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 3237 | } |
Ed Schouten | c66a5a3 | 2009-04-02 19:13:12 +0000 | [diff] [blame] | 3238 | |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 3239 | void freebsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3240 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3241 | const InputInfoList &Inputs, |
| 3242 | const ArgList &Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3243 | const char *LinkingOutput) const { |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 3244 | ArgStringList CmdArgs; |
| 3245 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3246 | // When building 32-bit code on FreeBSD/amd64, we have to explicitly |
| 3247 | // instruct as in the base system to assemble 32-bit code. |
| 3248 | if (getToolChain().getArchName() == "i386") |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 3249 | CmdArgs.push_back("--32"); |
| 3250 | |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3251 | |
Eric Christopher | ed73473 | 2010-03-02 02:41:08 +0000 | [diff] [blame] | 3252 | // Set byte order explicitly |
| 3253 | if (getToolChain().getArchName() == "mips") |
| 3254 | CmdArgs.push_back("-EB"); |
| 3255 | else if (getToolChain().getArchName() == "mipsel") |
| 3256 | CmdArgs.push_back("-EL"); |
| 3257 | |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 3258 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3259 | options::OPT_Xassembler); |
| 3260 | |
| 3261 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3262 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 3263 | |
| 3264 | for (InputInfoList::const_iterator |
| 3265 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3266 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3267 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 3268 | } |
| 3269 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3270 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3271 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3272 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 3273 | } |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3274 | |
| 3275 | void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3276 | const InputInfo &Output, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3277 | const InputInfoList &Inputs, |
| 3278 | const ArgList &Args, |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 3279 | const char *LinkingOutput) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3280 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3281 | ArgStringList CmdArgs; |
| 3282 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 3283 | if (!D.SysRoot.empty()) |
| 3284 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
| 3285 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3286 | if (Args.hasArg(options::OPT_static)) { |
| 3287 | CmdArgs.push_back("-Bstatic"); |
| 3288 | } else { |
Rafael Espindola | 65ba55d | 2010-11-11 02:17:51 +0000 | [diff] [blame] | 3289 | if (Args.hasArg(options::OPT_rdynamic)) |
| 3290 | CmdArgs.push_back("-export-dynamic"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3291 | CmdArgs.push_back("--eh-frame-hdr"); |
| 3292 | if (Args.hasArg(options::OPT_shared)) { |
| 3293 | CmdArgs.push_back("-Bshareable"); |
| 3294 | } else { |
| 3295 | CmdArgs.push_back("-dynamic-linker"); |
| 3296 | CmdArgs.push_back("/libexec/ld-elf.so.1"); |
| 3297 | } |
| 3298 | } |
| 3299 | |
| 3300 | // When building 32-bit code on FreeBSD/amd64, we have to explicitly |
| 3301 | // instruct ld in the base system to link 32-bit code. |
| 3302 | if (getToolChain().getArchName() == "i386") { |
| 3303 | CmdArgs.push_back("-m"); |
| 3304 | CmdArgs.push_back("elf_i386_fbsd"); |
| 3305 | } |
| 3306 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3307 | if (Output.isFilename()) { |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3308 | CmdArgs.push_back("-o"); |
| 3309 | CmdArgs.push_back(Output.getFilename()); |
| 3310 | } else { |
| 3311 | assert(Output.isNothing() && "Invalid output."); |
| 3312 | } |
| 3313 | |
| 3314 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3315 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 3316 | if (!Args.hasArg(options::OPT_shared)) { |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 3317 | if (Args.hasArg(options::OPT_pg)) |
| 3318 | CmdArgs.push_back(Args.MakeArgString( |
| 3319 | getToolChain().GetFilePath("gcrt1.o"))); |
| 3320 | else |
| 3321 | CmdArgs.push_back(Args.MakeArgString( |
| 3322 | getToolChain().GetFilePath("crt1.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3323 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3324 | getToolChain().GetFilePath("crti.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3325 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3326 | getToolChain().GetFilePath("crtbegin.o"))); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3327 | } else { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3328 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3329 | getToolChain().GetFilePath("crti.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3330 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3331 | getToolChain().GetFilePath("crtbeginS.o"))); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3332 | } |
| 3333 | } |
| 3334 | |
| 3335 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
Roman Divacky | 58e5ac9 | 2011-03-01 17:53:14 +0000 | [diff] [blame] | 3336 | const ToolChain::path_list Paths = getToolChain().getFilePaths(); |
| 3337 | for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end(); |
| 3338 | i != e; ++i) |
| 3339 | CmdArgs.push_back(Args.MakeArgString(llvm::StringRef("-L") + *i)); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3340 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 3341 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
David Chisnall | c736377 | 2010-08-15 22:58:12 +0000 | [diff] [blame] | 3342 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 3343 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 3344 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 3345 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3346 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 3347 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3348 | |
| 3349 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3350 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | 2002263 | 2010-02-17 08:07:51 +0000 | [diff] [blame] | 3351 | if (D.CCCIsCXX) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 3352 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 3353 | if (Args.hasArg(options::OPT_pg)) |
| 3354 | CmdArgs.push_back("-lm_p"); |
| 3355 | else |
| 3356 | CmdArgs.push_back("-lm"); |
Daniel Dunbar | 2002263 | 2010-02-17 08:07:51 +0000 | [diff] [blame] | 3357 | } |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3358 | // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding |
| 3359 | // the default system libraries. Just mimic this for now. |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 3360 | if (Args.hasArg(options::OPT_pg)) |
| 3361 | CmdArgs.push_back("-lgcc_p"); |
| 3362 | else |
| 3363 | CmdArgs.push_back("-lgcc"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3364 | if (Args.hasArg(options::OPT_static)) { |
| 3365 | CmdArgs.push_back("-lgcc_eh"); |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 3366 | } else if (Args.hasArg(options::OPT_pg)) { |
| 3367 | CmdArgs.push_back("-lgcc_eh_p"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3368 | } else { |
| 3369 | CmdArgs.push_back("--as-needed"); |
| 3370 | CmdArgs.push_back("-lgcc_s"); |
| 3371 | CmdArgs.push_back("--no-as-needed"); |
| 3372 | } |
| 3373 | |
Matt Beaumont-Gay | 2423026 | 2011-02-10 20:35:01 +0000 | [diff] [blame] | 3374 | if (Args.hasArg(options::OPT_pthread)) { |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 3375 | if (Args.hasArg(options::OPT_pg)) |
| 3376 | CmdArgs.push_back("-lpthread_p"); |
| 3377 | else |
| 3378 | CmdArgs.push_back("-lpthread"); |
Matt Beaumont-Gay | 2423026 | 2011-02-10 20:35:01 +0000 | [diff] [blame] | 3379 | } |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3380 | |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 3381 | if (Args.hasArg(options::OPT_pg)) { |
| 3382 | if (Args.hasArg(options::OPT_shared)) |
| 3383 | CmdArgs.push_back("-lc"); |
| 3384 | else |
| 3385 | CmdArgs.push_back("-lc_p"); |
| 3386 | CmdArgs.push_back("-lgcc_p"); |
| 3387 | } else { |
| 3388 | CmdArgs.push_back("-lc"); |
| 3389 | CmdArgs.push_back("-lgcc"); |
| 3390 | } |
| 3391 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3392 | if (Args.hasArg(options::OPT_static)) { |
| 3393 | CmdArgs.push_back("-lgcc_eh"); |
Roman Divacky | c16bb76 | 2011-02-10 16:59:40 +0000 | [diff] [blame] | 3394 | } else if (Args.hasArg(options::OPT_pg)) { |
| 3395 | CmdArgs.push_back("-lgcc_eh_p"); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3396 | } else { |
| 3397 | CmdArgs.push_back("--as-needed"); |
| 3398 | CmdArgs.push_back("-lgcc_s"); |
| 3399 | CmdArgs.push_back("--no-as-needed"); |
| 3400 | } |
| 3401 | } |
| 3402 | |
| 3403 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3404 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 3405 | if (!Args.hasArg(options::OPT_shared)) |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3406 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3407 | "crtend.o"))); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3408 | else |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3409 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3410 | "crtendS.o"))); |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3411 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3412 | "crtn.o"))); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3413 | } |
| 3414 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 3415 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3416 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3417 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 3418 | } |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3419 | |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3420 | void netbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 3421 | const InputInfo &Output, |
| 3422 | const InputInfoList &Inputs, |
| 3423 | const ArgList &Args, |
| 3424 | const char *LinkingOutput) const { |
| 3425 | ArgStringList CmdArgs; |
| 3426 | |
| 3427 | // When building 32-bit code on NetBSD/amd64, we have to explicitly |
| 3428 | // instruct as in the base system to assemble 32-bit code. |
| 3429 | if (getToolChain().getArchName() == "i386") |
| 3430 | CmdArgs.push_back("--32"); |
| 3431 | |
| 3432 | |
| 3433 | // Set byte order explicitly |
| 3434 | if (getToolChain().getArchName() == "mips") |
| 3435 | CmdArgs.push_back("-EB"); |
| 3436 | else if (getToolChain().getArchName() == "mipsel") |
| 3437 | CmdArgs.push_back("-EL"); |
| 3438 | |
| 3439 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3440 | options::OPT_Xassembler); |
| 3441 | |
| 3442 | CmdArgs.push_back("-o"); |
| 3443 | CmdArgs.push_back(Output.getFilename()); |
| 3444 | |
| 3445 | for (InputInfoList::const_iterator |
| 3446 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3447 | const InputInfo &II = *it; |
| 3448 | CmdArgs.push_back(II.getFilename()); |
| 3449 | } |
| 3450 | |
Joerg Sonnenberger | 10c6435 | 2011-03-21 14:01:40 +0000 | [diff] [blame] | 3451 | const char *Exec = Args.MakeArgString(FindTargetProgramPath(getToolChain(), |
| 3452 | "as")); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3453 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 3454 | } |
| 3455 | |
| 3456 | void netbsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 3457 | const InputInfo &Output, |
| 3458 | const InputInfoList &Inputs, |
| 3459 | const ArgList &Args, |
| 3460 | const char *LinkingOutput) const { |
| 3461 | const Driver &D = getToolChain().getDriver(); |
| 3462 | ArgStringList CmdArgs; |
| 3463 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 3464 | if (!D.SysRoot.empty()) |
| 3465 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
| 3466 | |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3467 | if (Args.hasArg(options::OPT_static)) { |
| 3468 | CmdArgs.push_back("-Bstatic"); |
| 3469 | } else { |
| 3470 | if (Args.hasArg(options::OPT_rdynamic)) |
| 3471 | CmdArgs.push_back("-export-dynamic"); |
| 3472 | CmdArgs.push_back("--eh-frame-hdr"); |
| 3473 | if (Args.hasArg(options::OPT_shared)) { |
| 3474 | CmdArgs.push_back("-Bshareable"); |
| 3475 | } else { |
| 3476 | CmdArgs.push_back("-dynamic-linker"); |
| 3477 | CmdArgs.push_back("/libexec/ld.elf_so"); |
| 3478 | } |
| 3479 | } |
| 3480 | |
| 3481 | // When building 32-bit code on NetBSD/amd64, we have to explicitly |
| 3482 | // instruct ld in the base system to link 32-bit code. |
| 3483 | if (getToolChain().getArchName() == "i386") { |
| 3484 | CmdArgs.push_back("-m"); |
| 3485 | CmdArgs.push_back("elf_i386"); |
| 3486 | } |
| 3487 | |
| 3488 | if (Output.isFilename()) { |
| 3489 | CmdArgs.push_back("-o"); |
| 3490 | CmdArgs.push_back(Output.getFilename()); |
| 3491 | } else { |
| 3492 | assert(Output.isNothing() && "Invalid output."); |
| 3493 | } |
| 3494 | |
| 3495 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3496 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 3497 | if (!Args.hasArg(options::OPT_shared)) { |
| 3498 | CmdArgs.push_back(Args.MakeArgString( |
| 3499 | getToolChain().GetFilePath("crt0.o"))); |
| 3500 | CmdArgs.push_back(Args.MakeArgString( |
| 3501 | getToolChain().GetFilePath("crti.o"))); |
| 3502 | CmdArgs.push_back(Args.MakeArgString( |
| 3503 | getToolChain().GetFilePath("crtbegin.o"))); |
| 3504 | } else { |
| 3505 | CmdArgs.push_back(Args.MakeArgString( |
| 3506 | getToolChain().GetFilePath("crti.o"))); |
| 3507 | CmdArgs.push_back(Args.MakeArgString( |
| 3508 | getToolChain().GetFilePath("crtbeginS.o"))); |
| 3509 | } |
| 3510 | } |
| 3511 | |
| 3512 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 3513 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 3514 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 3515 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 3516 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 3517 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 3518 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
| 3519 | |
| 3520 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
| 3521 | |
| 3522 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3523 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 3524 | if (D.CCCIsCXX) { |
| 3525 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
| 3526 | CmdArgs.push_back("-lm"); |
| 3527 | } |
| 3528 | // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding |
| 3529 | // the default system libraries. Just mimic this for now. |
| 3530 | CmdArgs.push_back("-lgcc"); |
| 3531 | if (Args.hasArg(options::OPT_static)) { |
| 3532 | CmdArgs.push_back("-lgcc_eh"); |
| 3533 | } else { |
| 3534 | CmdArgs.push_back("--as-needed"); |
| 3535 | CmdArgs.push_back("-lgcc_s"); |
| 3536 | CmdArgs.push_back("--no-as-needed"); |
| 3537 | } |
| 3538 | |
| 3539 | if (Args.hasArg(options::OPT_pthread)) |
| 3540 | CmdArgs.push_back("-lpthread"); |
| 3541 | CmdArgs.push_back("-lc"); |
| 3542 | |
| 3543 | CmdArgs.push_back("-lgcc"); |
| 3544 | if (Args.hasArg(options::OPT_static)) { |
| 3545 | CmdArgs.push_back("-lgcc_eh"); |
| 3546 | } else { |
| 3547 | CmdArgs.push_back("--as-needed"); |
| 3548 | CmdArgs.push_back("-lgcc_s"); |
| 3549 | CmdArgs.push_back("--no-as-needed"); |
| 3550 | } |
| 3551 | } |
| 3552 | |
| 3553 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3554 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 3555 | if (!Args.hasArg(options::OPT_shared)) |
| 3556 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
| 3557 | "crtend.o"))); |
| 3558 | else |
| 3559 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
| 3560 | "crtendS.o"))); |
| 3561 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
| 3562 | "crtn.o"))); |
| 3563 | } |
| 3564 | |
Joerg Sonnenberger | 10c6435 | 2011-03-21 14:01:40 +0000 | [diff] [blame] | 3565 | const char *Exec = Args.MakeArgString(FindTargetProgramPath(getToolChain(), |
| 3566 | "ld")); |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3567 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 3568 | } |
| 3569 | |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 3570 | void linuxtools::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 3571 | const InputInfo &Output, |
| 3572 | const InputInfoList &Inputs, |
| 3573 | const ArgList &Args, |
| 3574 | const char *LinkingOutput) const { |
| 3575 | ArgStringList CmdArgs; |
| 3576 | |
| 3577 | // Add --32/--64 to make sure we get the format we want. |
| 3578 | // This is incomplete |
| 3579 | if (getToolChain().getArch() == llvm::Triple::x86) { |
| 3580 | CmdArgs.push_back("--32"); |
| 3581 | } else if (getToolChain().getArch() == llvm::Triple::x86_64) { |
| 3582 | CmdArgs.push_back("--64"); |
| 3583 | } else if (getToolChain().getArch() == llvm::Triple::arm) { |
| 3584 | llvm::StringRef MArch = getToolChain().getArchName(); |
| 3585 | if (MArch == "armv7" || MArch == "armv7a" || MArch == "armv7-a") |
| 3586 | CmdArgs.push_back("-mfpu=neon"); |
| 3587 | } |
| 3588 | |
| 3589 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3590 | options::OPT_Xassembler); |
| 3591 | |
| 3592 | CmdArgs.push_back("-o"); |
| 3593 | CmdArgs.push_back(Output.getFilename()); |
| 3594 | |
| 3595 | for (InputInfoList::const_iterator |
| 3596 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3597 | const InputInfo &II = *it; |
| 3598 | CmdArgs.push_back(II.getFilename()); |
| 3599 | } |
| 3600 | |
| 3601 | const char *Exec = |
| 3602 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
| 3603 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 3604 | } |
| 3605 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3606 | void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 3607 | const InputInfo &Output, |
| 3608 | const InputInfoList &Inputs, |
| 3609 | const ArgList &Args, |
| 3610 | const char *LinkingOutput) const { |
| 3611 | const toolchains::Linux& ToolChain = |
| 3612 | static_cast<const toolchains::Linux&>(getToolChain()); |
| 3613 | const Driver &D = ToolChain.getDriver(); |
| 3614 | ArgStringList CmdArgs; |
| 3615 | |
Rafael Espindola | 26f14c3 | 2010-11-15 18:28:16 +0000 | [diff] [blame] | 3616 | // Silence warning for "clang -g foo.o -o foo" |
| 3617 | Args.ClaimAllArgs(options::OPT_g_Group); |
Rafael Espindola | 9c094fb | 2011-03-01 05:25:27 +0000 | [diff] [blame] | 3618 | // and "clang -emit-llvm foo.o -o foo" |
| 3619 | Args.ClaimAllArgs(options::OPT_emit_llvm); |
Rafael Espindola | 7f6458b | 2010-11-17 20:37:10 +0000 | [diff] [blame] | 3620 | // and for "clang -g foo.o -o foo". Other warning options are already |
| 3621 | // handled somewhere else. |
| 3622 | Args.ClaimAllArgs(options::OPT_w); |
Rafael Espindola | 26f14c3 | 2010-11-15 18:28:16 +0000 | [diff] [blame] | 3623 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 3624 | if (!D.SysRoot.empty()) |
| 3625 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3626 | |
Rafael Espindola | fdda171 | 2010-11-17 22:26:15 +0000 | [diff] [blame] | 3627 | if (Args.hasArg(options::OPT_pie)) |
| 3628 | CmdArgs.push_back("-pie"); |
| 3629 | |
Rafael Espindola | dc1b76d | 2010-11-07 22:57:16 +0000 | [diff] [blame] | 3630 | if (Args.hasArg(options::OPT_rdynamic)) |
| 3631 | CmdArgs.push_back("-export-dynamic"); |
| 3632 | |
Rafael Espindola | e0e6d3b | 2010-11-11 19:34:42 +0000 | [diff] [blame] | 3633 | if (Args.hasArg(options::OPT_s)) |
| 3634 | CmdArgs.push_back("-s"); |
| 3635 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3636 | for (std::vector<std::string>::const_iterator i = ToolChain.ExtraOpts.begin(), |
| 3637 | e = ToolChain.ExtraOpts.end(); |
| 3638 | i != e; ++i) |
| 3639 | CmdArgs.push_back(i->c_str()); |
| 3640 | |
| 3641 | if (!Args.hasArg(options::OPT_static)) { |
| 3642 | CmdArgs.push_back("--eh-frame-hdr"); |
| 3643 | } |
| 3644 | |
| 3645 | CmdArgs.push_back("-m"); |
| 3646 | if (ToolChain.getArch() == llvm::Triple::x86) |
| 3647 | CmdArgs.push_back("elf_i386"); |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 3648 | else if (ToolChain.getArch() == llvm::Triple::arm |
| 3649 | || ToolChain.getArch() == llvm::Triple::thumb) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3650 | CmdArgs.push_back("armelf_linux_eabi"); |
| 3651 | else |
| 3652 | CmdArgs.push_back("elf_x86_64"); |
| 3653 | |
| 3654 | if (Args.hasArg(options::OPT_static)) { |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 3655 | if (ToolChain.getArch() == llvm::Triple::arm |
| 3656 | || ToolChain.getArch() == llvm::Triple::thumb) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3657 | CmdArgs.push_back("-Bstatic"); |
| 3658 | else |
| 3659 | CmdArgs.push_back("-static"); |
| 3660 | } else if (Args.hasArg(options::OPT_shared)) { |
| 3661 | CmdArgs.push_back("-shared"); |
| 3662 | } |
| 3663 | |
| 3664 | if (ToolChain.getArch() == llvm::Triple::arm || |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 3665 | ToolChain.getArch() == llvm::Triple::thumb || |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3666 | (!Args.hasArg(options::OPT_static) && |
| 3667 | !Args.hasArg(options::OPT_shared))) { |
| 3668 | CmdArgs.push_back("-dynamic-linker"); |
| 3669 | if (ToolChain.getArch() == llvm::Triple::x86) |
| 3670 | CmdArgs.push_back("/lib/ld-linux.so.2"); |
Douglas Gregor | f0594d8 | 2011-03-06 19:11:49 +0000 | [diff] [blame] | 3671 | else if (ToolChain.getArch() == llvm::Triple::arm || |
| 3672 | ToolChain.getArch() == llvm::Triple::thumb) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3673 | CmdArgs.push_back("/lib/ld-linux.so.3"); |
| 3674 | else |
| 3675 | CmdArgs.push_back("/lib64/ld-linux-x86-64.so.2"); |
| 3676 | } |
| 3677 | |
| 3678 | CmdArgs.push_back("-o"); |
| 3679 | CmdArgs.push_back(Output.getFilename()); |
| 3680 | |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 3681 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3682 | !Args.hasArg(options::OPT_nostartfiles)) { |
Rafael Espindola | fdda171 | 2010-11-17 22:26:15 +0000 | [diff] [blame] | 3683 | const char *crt1 = NULL; |
| 3684 | if (!Args.hasArg(options::OPT_shared)){ |
| 3685 | if (Args.hasArg(options::OPT_pie)) |
| 3686 | crt1 = "Scrt1.o"; |
| 3687 | else |
| 3688 | crt1 = "crt1.o"; |
| 3689 | } |
| 3690 | if (crt1) |
| 3691 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1))); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3692 | |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 3693 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3694 | |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 3695 | const char *crtbegin; |
| 3696 | if (Args.hasArg(options::OPT_static)) |
| 3697 | crtbegin = "crtbeginT.o"; |
Rafael Espindola | fdda171 | 2010-11-17 22:26:15 +0000 | [diff] [blame] | 3698 | else if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 3699 | crtbegin = "crtbeginS.o"; |
| 3700 | else |
| 3701 | crtbegin = "crtbegin.o"; |
| 3702 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); |
| 3703 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3704 | |
| 3705 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 3706 | |
| 3707 | const ToolChain::path_list Paths = ToolChain.getFilePaths(); |
| 3708 | |
Roman Divacky | 58e5ac9 | 2011-03-01 17:53:14 +0000 | [diff] [blame] | 3709 | for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end(); |
| 3710 | i != e; ++i) |
| 3711 | CmdArgs.push_back(Args.MakeArgString(llvm::StringRef("-L") + *i)); |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3712 | |
| 3713 | AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs); |
| 3714 | |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 3715 | if (D.CCCIsCXX && !Args.hasArg(options::OPT_nostdlib)) { |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3716 | ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); |
| 3717 | CmdArgs.push_back("-lm"); |
| 3718 | } |
| 3719 | |
| 3720 | if (Args.hasArg(options::OPT_static)) |
| 3721 | CmdArgs.push_back("--start-group"); |
| 3722 | |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 3723 | if (!Args.hasArg(options::OPT_nostdlib)) { |
| 3724 | if (!D.CCCIsCXX) |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3725 | CmdArgs.push_back("-lgcc"); |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 3726 | |
| 3727 | if (Args.hasArg(options::OPT_static)) { |
| 3728 | if (D.CCCIsCXX) |
| 3729 | CmdArgs.push_back("-lgcc"); |
| 3730 | } else { |
| 3731 | if (!D.CCCIsCXX) |
| 3732 | CmdArgs.push_back("--as-needed"); |
| 3733 | CmdArgs.push_back("-lgcc_s"); |
| 3734 | if (!D.CCCIsCXX) |
| 3735 | CmdArgs.push_back("--no-as-needed"); |
| 3736 | } |
| 3737 | |
| 3738 | if (Args.hasArg(options::OPT_static)) |
| 3739 | CmdArgs.push_back("-lgcc_eh"); |
| 3740 | else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX) |
| 3741 | CmdArgs.push_back("-lgcc"); |
| 3742 | |
| 3743 | if (Args.hasArg(options::OPT_pthread) || |
| 3744 | Args.hasArg(options::OPT_pthreads)) |
| 3745 | CmdArgs.push_back("-lpthread"); |
| 3746 | |
| 3747 | CmdArgs.push_back("-lc"); |
| 3748 | |
| 3749 | if (Args.hasArg(options::OPT_static)) |
| 3750 | CmdArgs.push_back("--end-group"); |
| 3751 | else { |
| 3752 | if (!D.CCCIsCXX) |
| 3753 | CmdArgs.push_back("-lgcc"); |
| 3754 | |
| 3755 | if (!D.CCCIsCXX) |
| 3756 | CmdArgs.push_back("--as-needed"); |
| 3757 | CmdArgs.push_back("-lgcc_s"); |
| 3758 | if (!D.CCCIsCXX) |
| 3759 | CmdArgs.push_back("--no-as-needed"); |
| 3760 | |
| 3761 | if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX) |
| 3762 | CmdArgs.push_back("-lgcc"); |
| 3763 | } |
| 3764 | |
Rafael Espindola | fdda171 | 2010-11-17 22:26:15 +0000 | [diff] [blame] | 3765 | |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 3766 | if (!Args.hasArg(options::OPT_nostartfiles)) { |
| 3767 | const char *crtend; |
| 3768 | if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie)) |
| 3769 | crtend = "crtendS.o"; |
| 3770 | else |
| 3771 | crtend = "crtend.o"; |
Rafael Espindola | 89414b3 | 2010-11-12 03:00:39 +0000 | [diff] [blame] | 3772 | |
Rafael Espindola | 49c64fd | 2010-12-01 01:52:43 +0000 | [diff] [blame] | 3773 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend))); |
| 3774 | CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); |
| 3775 | } |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3776 | } |
| 3777 | |
Rafael Espindola | c1da981 | 2010-11-07 20:14:31 +0000 | [diff] [blame] | 3778 | if (Args.hasArg(options::OPT_use_gold_plugin)) { |
| 3779 | CmdArgs.push_back("-plugin"); |
| 3780 | std::string Plugin = ToolChain.getDriver().Dir + "/../lib/LLVMgold.so"; |
| 3781 | CmdArgs.push_back(Args.MakeArgString(Plugin)); |
| 3782 | } |
| 3783 | |
| 3784 | C.addCommand(new Command(JA, *this, ToolChain.Linker.c_str(), CmdArgs)); |
| 3785 | } |
Rafael Espindola | ba30bbe | 2010-08-10 00:25:48 +0000 | [diff] [blame] | 3786 | |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3787 | void minix::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3788 | const InputInfo &Output, |
| 3789 | const InputInfoList &Inputs, |
| 3790 | const ArgList &Args, |
| 3791 | const char *LinkingOutput) const { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3792 | ArgStringList CmdArgs; |
| 3793 | |
| 3794 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3795 | options::OPT_Xassembler); |
| 3796 | |
| 3797 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3798 | CmdArgs.push_back(Output.getFilename()); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3799 | |
| 3800 | for (InputInfoList::const_iterator |
| 3801 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3802 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3803 | CmdArgs.push_back(II.getFilename()); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3804 | } |
| 3805 | |
| 3806 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3807 | Args.MakeArgString(getToolChain().GetProgramPath("gas")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3808 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | void minix::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3812 | const InputInfo &Output, |
| 3813 | const InputInfoList &Inputs, |
| 3814 | const ArgList &Args, |
| 3815 | const char *LinkingOutput) const { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3816 | const Driver &D = getToolChain().getDriver(); |
| 3817 | ArgStringList CmdArgs; |
| 3818 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3819 | if (Output.isFilename()) { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3820 | CmdArgs.push_back("-o"); |
| 3821 | CmdArgs.push_back(Output.getFilename()); |
| 3822 | } else { |
| 3823 | assert(Output.isNothing() && "Invalid output."); |
| 3824 | } |
| 3825 | |
| 3826 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3827 | !Args.hasArg(options::OPT_nostartfiles)) |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3828 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3829 | "/usr/gnu/lib/crtso.o"))); |
| 3830 | |
| 3831 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 3832 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 3833 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 3834 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 3835 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3836 | |
| 3837 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3838 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 3839 | if (D.CCCIsCXX) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 3840 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3841 | CmdArgs.push_back("-lm"); |
| 3842 | } |
| 3843 | |
| 3844 | if (Args.hasArg(options::OPT_pthread)) |
| 3845 | CmdArgs.push_back("-lpthread"); |
| 3846 | CmdArgs.push_back("-lc"); |
| 3847 | CmdArgs.push_back("-lgcc"); |
| 3848 | CmdArgs.push_back("-L/usr/gnu/lib"); |
| 3849 | // FIXME: fill in the correct search path for the final |
| 3850 | // support libraries. |
| 3851 | CmdArgs.push_back("-L/usr/gnu/lib/gcc/i686-pc-minix/4.4.3"); |
| 3852 | } |
| 3853 | |
| 3854 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3855 | !Args.hasArg(options::OPT_nostartfiles)) { |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3856 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath( |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3857 | "/usr/gnu/lib/libend.a"))); |
| 3858 | } |
| 3859 | |
| 3860 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3861 | Args.MakeArgString(getToolChain().GetProgramPath("/usr/gnu/bin/gld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3862 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3863 | } |
| 3864 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3865 | /// DragonFly Tools |
| 3866 | |
| 3867 | // For now, DragonFly Assemble does just about the same as for |
| 3868 | // FreeBSD, but this may change soon. |
| 3869 | void dragonfly::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3870 | const InputInfo &Output, |
Daniel Dunbar | 294691e | 2009-11-04 06:24:38 +0000 | [diff] [blame] | 3871 | const InputInfoList &Inputs, |
| 3872 | const ArgList &Args, |
| 3873 | const char *LinkingOutput) const { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3874 | ArgStringList CmdArgs; |
| 3875 | |
| 3876 | // When building 32-bit code on DragonFly/pc64, we have to explicitly |
| 3877 | // instruct as in the base system to assemble 32-bit code. |
| 3878 | if (getToolChain().getArchName() == "i386") |
| 3879 | CmdArgs.push_back("--32"); |
| 3880 | |
| 3881 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 3882 | options::OPT_Xassembler); |
| 3883 | |
| 3884 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3885 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3886 | |
| 3887 | for (InputInfoList::const_iterator |
| 3888 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 3889 | const InputInfo &II = *it; |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3890 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3894 | Args.MakeArgString(getToolChain().GetProgramPath("as")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3895 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | void dragonfly::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 3899 | const InputInfo &Output, |
| 3900 | const InputInfoList &Inputs, |
| 3901 | const ArgList &Args, |
| 3902 | const char *LinkingOutput) const { |
Daniel Dunbar | ee788e7 | 2009-12-21 18:54:17 +0000 | [diff] [blame] | 3903 | const Driver &D = getToolChain().getDriver(); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3904 | ArgStringList CmdArgs; |
| 3905 | |
Joerg Sonnenberger | 8ab2bdc | 2011-03-21 13:51:29 +0000 | [diff] [blame] | 3906 | if (!D.SysRoot.empty()) |
| 3907 | CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); |
| 3908 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3909 | if (Args.hasArg(options::OPT_static)) { |
| 3910 | CmdArgs.push_back("-Bstatic"); |
| 3911 | } else { |
| 3912 | if (Args.hasArg(options::OPT_shared)) |
| 3913 | CmdArgs.push_back("-Bshareable"); |
| 3914 | else { |
| 3915 | CmdArgs.push_back("-dynamic-linker"); |
| 3916 | CmdArgs.push_back("/usr/libexec/ld-elf.so.2"); |
| 3917 | } |
| 3918 | } |
| 3919 | |
| 3920 | // When building 32-bit code on DragonFly/pc64, we have to explicitly |
| 3921 | // instruct ld in the base system to link 32-bit code. |
| 3922 | if (getToolChain().getArchName() == "i386") { |
| 3923 | CmdArgs.push_back("-m"); |
| 3924 | CmdArgs.push_back("elf_i386"); |
| 3925 | } |
| 3926 | |
Daniel Dunbar | 7c1e465 | 2010-08-02 02:38:21 +0000 | [diff] [blame] | 3927 | if (Output.isFilename()) { |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3928 | CmdArgs.push_back("-o"); |
| 3929 | CmdArgs.push_back(Output.getFilename()); |
| 3930 | } else { |
| 3931 | assert(Output.isNothing() && "Invalid output."); |
| 3932 | } |
| 3933 | |
| 3934 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3935 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 3936 | if (!Args.hasArg(options::OPT_shared)) { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3937 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3938 | Args.MakeArgString(getToolChain().GetFilePath("crt1.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3939 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3940 | Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3941 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3942 | Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o"))); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3943 | } else { |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3944 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3945 | Args.MakeArgString(getToolChain().GetFilePath("crti.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 3946 | CmdArgs.push_back( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 3947 | Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.o"))); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3948 | } |
| 3949 | } |
| 3950 | |
| 3951 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 3952 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 3953 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 3954 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 3955 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3956 | |
| 3957 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 3958 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 3959 | // FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of |
| 3960 | // rpaths |
| 3961 | CmdArgs.push_back("-L/usr/lib/gcc41"); |
| 3962 | |
| 3963 | if (!Args.hasArg(options::OPT_static)) { |
| 3964 | CmdArgs.push_back("-rpath"); |
| 3965 | CmdArgs.push_back("/usr/lib/gcc41"); |
| 3966 | |
| 3967 | CmdArgs.push_back("-rpath-link"); |
| 3968 | CmdArgs.push_back("/usr/lib/gcc41"); |
| 3969 | |
| 3970 | CmdArgs.push_back("-rpath"); |
| 3971 | CmdArgs.push_back("/usr/lib"); |
| 3972 | |
| 3973 | CmdArgs.push_back("-rpath-link"); |
| 3974 | CmdArgs.push_back("/usr/lib"); |
| 3975 | } |
| 3976 | |
Rafael Espindola | 405861d | 2010-07-20 12:59:03 +0000 | [diff] [blame] | 3977 | if (D.CCCIsCXX) { |
Daniel Dunbar | 132e35d | 2010-09-17 01:20:05 +0000 | [diff] [blame] | 3978 | getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs); |
Rafael Espindola | 405861d | 2010-07-20 12:59:03 +0000 | [diff] [blame] | 3979 | CmdArgs.push_back("-lm"); |
| 3980 | } |
| 3981 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3982 | if (Args.hasArg(options::OPT_shared)) { |
| 3983 | CmdArgs.push_back("-lgcc_pic"); |
| 3984 | } else { |
| 3985 | CmdArgs.push_back("-lgcc"); |
| 3986 | } |
| 3987 | |
| 3988 | |
| 3989 | if (Args.hasArg(options::OPT_pthread)) |
Mike Stump | 4d63f8b | 2009-10-31 20:11:46 +0000 | [diff] [blame] | 3990 | CmdArgs.push_back("-lpthread"); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 3991 | |
| 3992 | if (!Args.hasArg(options::OPT_nolibc)) { |
| 3993 | CmdArgs.push_back("-lc"); |
| 3994 | } |
| 3995 | |
| 3996 | if (Args.hasArg(options::OPT_shared)) { |
| 3997 | CmdArgs.push_back("-lgcc_pic"); |
| 3998 | } else { |
| 3999 | CmdArgs.push_back("-lgcc"); |
| 4000 | } |
| 4001 | } |
| 4002 | |
| 4003 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4004 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4005 | if (!Args.hasArg(options::OPT_shared)) |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4006 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4007 | getToolChain().GetFilePath("crtend.o"))); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4008 | else |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4009 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4010 | getToolChain().GetFilePath("crtendS.o"))); |
Chris Lattner | 38e317d | 2010-07-07 16:01:42 +0000 | [diff] [blame] | 4011 | CmdArgs.push_back(Args.MakeArgString( |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4012 | getToolChain().GetFilePath("crtn.o"))); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4013 | } |
| 4014 | |
| 4015 | const char *Exec = |
Daniel Dunbar | 4a7e889 | 2010-07-14 18:46:23 +0000 | [diff] [blame] | 4016 | Args.MakeArgString(getToolChain().GetProgramPath("ld")); |
Daniel Dunbar | 2fe238e | 2010-08-02 02:38:28 +0000 | [diff] [blame] | 4017 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 4018 | } |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 4019 | |
| 4020 | void visualstudio::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 4021 | const InputInfo &Output, |
| 4022 | const InputInfoList &Inputs, |
| 4023 | const ArgList &Args, |
| 4024 | const char *LinkingOutput) const { |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 4025 | ArgStringList CmdArgs; |
| 4026 | |
| 4027 | if (Output.isFilename()) { |
Daniel Dunbar | e5a37f4 | 2010-09-17 00:45:02 +0000 | [diff] [blame] | 4028 | CmdArgs.push_back(Args.MakeArgString(std::string("-out:") + |
| 4029 | Output.getFilename())); |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 4030 | } else { |
| 4031 | assert(Output.isNothing() && "Invalid output."); |
| 4032 | } |
| 4033 | |
| 4034 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 4035 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 4036 | CmdArgs.push_back("-defaultlib:libcmt"); |
| 4037 | } |
| 4038 | |
| 4039 | CmdArgs.push_back("-nologo"); |
| 4040 | |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 4041 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 4042 | |
| 4043 | const char *Exec = |
Daniel Dunbar | 2008fee | 2010-09-17 00:24:54 +0000 | [diff] [blame] | 4044 | Args.MakeArgString(getToolChain().GetProgramPath("link.exe")); |
Michael J. Spencer | ff58e36 | 2010-08-21 21:55:07 +0000 | [diff] [blame] | 4045 | C.addCommand(new Command(JA, *this, Exec, CmdArgs)); |
| 4046 | } |