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