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