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