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