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