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