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