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 | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Driver.h" // FIXME: Remove? |
| 16 | #include "clang/Driver/DriverDiagnostic.h" // FIXME: Remove? |
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" |
| 21 | #include "clang/Driver/ToolChain.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 22 | #include "clang/Driver/Util.h" |
| 23 | |
| 24 | #include "llvm/ADT/SmallVector.h" |
Daniel Dunbar | 5b750fe | 2009-09-09 22:32:34 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/Twine.h" |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Format.h" |
| 27 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 28 | |
| 29 | #include "InputInfo.h" |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 30 | #include "ToolChains.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 31 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 32 | using namespace clang::driver; |
| 33 | using namespace clang::driver::tools; |
| 34 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 35 | static const char *MakeFormattedString(const ArgList &Args, |
| 36 | const llvm::format_object_base &Fmt) { |
| 37 | std::string Str; |
| 38 | llvm::raw_string_ostream(Str) << Fmt; |
| 39 | return Args.MakeArgString(Str.c_str()); |
| 40 | } |
| 41 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 42 | void Clang::AddPreprocessingOptions(const Driver &D, |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 43 | const ArgList &Args, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 44 | ArgStringList &CmdArgs, |
| 45 | const InputInfo &Output, |
| 46 | const InputInfoList &Inputs) const { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 47 | Arg *A; |
Daniel Dunbar | 3a183d3 | 2009-06-08 21:48:20 +0000 | [diff] [blame] | 48 | |
| 49 | if ((A = Args.getLastArg(options::OPT_C)) || |
| 50 | (A = Args.getLastArg(options::OPT_CC))) { |
| 51 | if (!Args.hasArg(options::OPT_E)) |
| 52 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 53 | << A->getAsString(Args) << "-E"; |
| 54 | A->render(Args, CmdArgs); |
| 55 | } |
| 56 | |
| 57 | // Handle dependency file generation. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 58 | if ((A = Args.getLastArg(options::OPT_M)) || |
| 59 | (A = Args.getLastArg(options::OPT_MM)) || |
| 60 | (A = Args.getLastArg(options::OPT_MD)) || |
| 61 | (A = Args.getLastArg(options::OPT_MMD))) { |
| 62 | // Determine the output location. |
| 63 | const char *DepFile; |
| 64 | if (Output.getType() == types::TY_Dependencies) { |
| 65 | if (Output.isPipe()) |
| 66 | DepFile = "-"; |
| 67 | else |
| 68 | DepFile = Output.getFilename(); |
| 69 | } else if (Arg *MF = Args.getLastArg(options::OPT_MF)) { |
| 70 | DepFile = MF->getValue(Args); |
| 71 | } else if (A->getOption().getId() == options::OPT_M || |
| 72 | A->getOption().getId() == options::OPT_MM) { |
| 73 | DepFile = "-"; |
| 74 | } else { |
| 75 | DepFile = darwin::CC1::getDependencyFileName(Args, Inputs); |
| 76 | } |
| 77 | CmdArgs.push_back("-dependency-file"); |
| 78 | CmdArgs.push_back(DepFile); |
| 79 | |
| 80 | // Add an -MT option if the user didn't specify their own. |
Daniel Dunbar | e0be8b1 | 2009-09-08 16:39:16 +0000 | [diff] [blame] | 81 | // |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 82 | // FIXME: This should use -MQ, when we support it. |
| 83 | if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) { |
| 84 | const char *DepTarget; |
| 85 | |
| 86 | // If user provided -o, that is the dependency target, except |
| 87 | // when we are only generating a dependency file. |
| 88 | Arg *OutputOpt = Args.getLastArg(options::OPT_o); |
| 89 | if (OutputOpt && Output.getType() != types::TY_Dependencies) { |
| 90 | DepTarget = OutputOpt->getValue(Args); |
| 91 | } else { |
| 92 | // Otherwise derive from the base input. |
| 93 | // |
| 94 | // FIXME: This should use the computed output file location. |
| 95 | llvm::sys::Path P(Inputs[0].getBaseInput()); |
| 96 | |
| 97 | P.eraseSuffix(); |
| 98 | P.appendSuffix("o"); |
| 99 | DepTarget = Args.MakeArgString(P.getLast().c_str()); |
| 100 | } |
| 101 | |
| 102 | CmdArgs.push_back("-MT"); |
| 103 | CmdArgs.push_back(DepTarget); |
| 104 | } |
| 105 | |
| 106 | if (A->getOption().getId() == options::OPT_M || |
| 107 | A->getOption().getId() == options::OPT_MD) |
| 108 | CmdArgs.push_back("-sys-header-deps"); |
| 109 | } |
| 110 | |
| 111 | Args.AddLastArg(CmdArgs, options::OPT_MP); |
| 112 | Args.AddAllArgs(CmdArgs, options::OPT_MT); |
| 113 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 114 | // Add -i* options, and automatically translate to |
| 115 | // -include-pch/-include-pth for transparent PCH support. It's |
| 116 | // wonky, but we include looking for .gch so we can support seamless |
| 117 | // replacement into a build system already set up to be generating |
| 118 | // .gch files. |
Daniel Dunbar | e0be8b1 | 2009-09-08 16:39:16 +0000 | [diff] [blame] | 119 | // |
| 120 | // FIXME: Use iterator. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 121 | for (ArgList::const_iterator |
| 122 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 123 | const Arg *A = *it; |
| 124 | if (!A->getOption().matches(options::OPT_clang_i_Group)) |
| 125 | continue; |
| 126 | |
| 127 | if (A->getOption().matches(options::OPT_include)) { |
| 128 | bool FoundPTH = false; |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 129 | bool FoundPCH = false; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 130 | llvm::sys::Path P(A->getValue(Args)); |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 131 | if (D.CCCUsePCH) { |
| 132 | P.appendSuffix("pch"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 133 | if (P.exists()) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 134 | FoundPCH = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 135 | else |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 136 | P.eraseSuffix(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 139 | if (!FoundPCH) { |
| 140 | P.appendSuffix("pth"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 141 | if (P.exists()) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 142 | FoundPTH = true; |
| 143 | else |
| 144 | P.eraseSuffix(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 147 | if (!FoundPCH && !FoundPTH) { |
| 148 | P.appendSuffix("gch"); |
| 149 | if (P.exists()) { |
| 150 | FoundPCH = D.CCCUsePCH; |
| 151 | FoundPTH = !D.CCCUsePCH; |
| 152 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | else |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 154 | P.eraseSuffix(); |
| 155 | } |
| 156 | |
| 157 | if (FoundPCH || FoundPTH) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 158 | A->claim(); |
Daniel Dunbar | ea71a5b | 2009-04-28 19:38:45 +0000 | [diff] [blame] | 159 | if (D.CCCUsePCH) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 160 | CmdArgs.push_back("-include-pch"); |
| 161 | else |
| 162 | CmdArgs.push_back("-include-pth"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 163 | CmdArgs.push_back(Args.MakeArgString(P.c_str())); |
| 164 | continue; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | // Not translated, render as usual. |
| 169 | A->claim(); |
| 170 | A->render(Args, CmdArgs); |
| 171 | } |
| 172 | |
| 173 | Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U); |
| 174 | Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F); |
| 175 | |
| 176 | // Add -Wp, and -Xassembler if using the preprocessor. |
| 177 | |
| 178 | // FIXME: There is a very unfortunate problem here, some troubled |
| 179 | // souls abuse -Wp, to pass preprocessor options in gcc syntax. To |
| 180 | // really support that we would have to parse and then translate |
| 181 | // those options. :( |
| 182 | Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA, |
| 183 | options::OPT_Xpreprocessor); |
| 184 | } |
| 185 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 186 | void Clang::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 187 | Job &Dest, |
| 188 | const InputInfo &Output, |
Daniel Dunbar | 62cf601 | 2009-03-18 06:07:59 +0000 | [diff] [blame] | 189 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 190 | const ArgList &Args, |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 191 | const char *LinkingOutput) const { |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 192 | const Driver &D = getToolChain().getHost().getDriver(); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 193 | ArgStringList CmdArgs; |
| 194 | |
Daniel Dunbar | 077ba6a | 2009-03-31 20:53:55 +0000 | [diff] [blame] | 195 | assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); |
| 196 | |
Daniel Dunbar | af07f93 | 2009-03-31 17:35:15 +0000 | [diff] [blame] | 197 | CmdArgs.push_back("-triple"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 198 | const char *TripleStr = |
Daniel Dunbar | af07f93 | 2009-03-31 17:35:15 +0000 | [diff] [blame] | 199 | Args.MakeArgString(getToolChain().getTripleString().c_str()); |
| 200 | CmdArgs.push_back(TripleStr); |
| 201 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 202 | if (isa<AnalyzeJobAction>(JA)) { |
| 203 | assert(JA.getType() == types::TY_Plist && "Invalid output type."); |
| 204 | CmdArgs.push_back("-analyze"); |
| 205 | } else if (isa<PreprocessJobAction>(JA)) { |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 206 | if (Output.getType() == types::TY_Dependencies) |
| 207 | CmdArgs.push_back("-Eonly"); |
| 208 | else |
| 209 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 210 | } else if (isa<PrecompileJobAction>(JA)) { |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 211 | if (D.CCCUsePCH) |
| 212 | CmdArgs.push_back("-emit-pch"); |
| 213 | else |
| 214 | CmdArgs.push_back("-emit-pth"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 215 | } else { |
| 216 | assert(isa<CompileJobAction>(JA) && "Invalid action for clang tool."); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 217 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 218 | if (JA.getType() == types::TY_Nothing) { |
| 219 | CmdArgs.push_back("-fsyntax-only"); |
| 220 | } else if (JA.getType() == types::TY_LLVMAsm) { |
| 221 | CmdArgs.push_back("-emit-llvm"); |
| 222 | } else if (JA.getType() == types::TY_LLVMBC) { |
| 223 | CmdArgs.push_back("-emit-llvm-bc"); |
| 224 | } else if (JA.getType() == types::TY_PP_Asm) { |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 225 | if (Inputs[0].getType() == types::TY_AST) |
| 226 | CmdArgs.push_back("-compile-ast"); |
| 227 | else |
| 228 | CmdArgs.push_back("-S"); |
| 229 | } else if (JA.getType() == types::TY_AST) { |
| 230 | CmdArgs.push_back("-emit-pch"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 231 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 234 | // The make clang go fast button. |
| 235 | CmdArgs.push_back("-disable-free"); |
| 236 | |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 237 | // Set the main file name, so that debug info works even with |
| 238 | // -save-temps. |
| 239 | CmdArgs.push_back("-main-file-name"); |
| 240 | CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs)); |
| 241 | |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 242 | // Some flags which affect the language (via preprocessor |
| 243 | // defines). See darwin::CC1::AddCPPArgs. |
| 244 | if (Args.hasArg(options::OPT_static)) |
| 245 | CmdArgs.push_back("-static-define"); |
| 246 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 247 | if (isa<AnalyzeJobAction>(JA)) { |
| 248 | // Add default argument set. |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 249 | if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) { |
| 250 | CmdArgs.push_back("-warn-dead-stores"); |
Ted Kremenek | 1172751 | 2009-07-24 20:03:11 +0000 | [diff] [blame] | 251 | CmdArgs.push_back("-warn-security-syntactic"); |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 252 | CmdArgs.push_back("-checker-cfref"); |
| 253 | CmdArgs.push_back("-analyzer-eagerly-assume"); |
| 254 | CmdArgs.push_back("-warn-objc-methodsigs"); |
| 255 | // Do not enable the missing -dealloc check. |
| 256 | // '-warn-objc-missing-dealloc', |
| 257 | CmdArgs.push_back("-warn-objc-unused-ivars"); |
| 258 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 259 | |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 260 | // Set the output format. The default is plist, for (lame) historical |
| 261 | // reasons. |
| 262 | CmdArgs.push_back("-analyzer-output"); |
| 263 | if (Arg *A = Args.getLastArg(options::OPT__analyzer_output)) |
| 264 | CmdArgs.push_back(A->getValue(Args)); |
| 265 | else |
| 266 | CmdArgs.push_back("plist"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 267 | |
| 268 | // Add -Xanalyzer arguments when running as analyzer. |
| 269 | Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 272 | // Perform argument translation for LLVM backend. This |
| 273 | // takes some care in reconciling with llvm-gcc. The |
| 274 | // issue is that llvm-gcc translates these options based on |
| 275 | // the values in cc1, whereas we are processing based on |
| 276 | // the driver arguments. |
| 277 | // |
| 278 | // FIXME: This is currently broken for -f flags when -fno |
| 279 | // variants are present. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 280 | |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 281 | // This comes from the default translation the driver + cc1 |
| 282 | // would do to enable flag_pic. |
| 283 | // |
| 284 | // FIXME: Centralize this code. |
| 285 | bool PICEnabled = (Args.hasArg(options::OPT_fPIC) || |
| 286 | Args.hasArg(options::OPT_fpic) || |
| 287 | Args.hasArg(options::OPT_fPIE) || |
| 288 | Args.hasArg(options::OPT_fpie)); |
| 289 | bool PICDisabled = (Args.hasArg(options::OPT_mkernel) || |
| 290 | Args.hasArg(options::OPT_static)); |
| 291 | const char *Model = getToolChain().GetForcedPicModel(); |
| 292 | if (!Model) { |
| 293 | if (Args.hasArg(options::OPT_mdynamic_no_pic)) |
| 294 | Model = "dynamic-no-pic"; |
| 295 | else if (PICDisabled) |
| 296 | Model = "static"; |
| 297 | else if (PICEnabled) |
| 298 | Model = "pic"; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 299 | else |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 300 | Model = getToolChain().GetDefaultRelocationModel(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 301 | } |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 302 | CmdArgs.push_back("--relocation-model"); |
| 303 | CmdArgs.push_back(Model); |
| 304 | |
| 305 | // Infer the __PIC__ value. |
| 306 | // |
| 307 | // FIXME: This isn't quite right on Darwin, which always sets |
| 308 | // __PIC__=2. |
| 309 | if (strcmp(Model, "pic") == 0 || strcmp(Model, "dynamic-no-pic") == 0) { |
| 310 | if (Args.hasArg(options::OPT_fPIC)) |
| 311 | CmdArgs.push_back("-pic-level=2"); |
| 312 | else |
| 313 | CmdArgs.push_back("-pic-level=1"); |
| 314 | } |
| 315 | |
| 316 | if (Args.hasArg(options::OPT_ftime_report)) |
| 317 | CmdArgs.push_back("--time-passes"); |
| 318 | // FIXME: Set --enable-unsafe-fp-math. |
Benjamin Kramer | 21656dd | 2009-08-05 19:47:38 +0000 | [diff] [blame] | 319 | if (Args.hasFlag(options::OPT_fno_omit_frame_pointer, |
| 320 | options::OPT_fomit_frame_pointer)) |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 321 | CmdArgs.push_back("--disable-fp-elim"); |
| 322 | if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss, |
| 323 | options::OPT_fno_zero_initialized_in_bss, |
| 324 | true)) |
| 325 | CmdArgs.push_back("--nozero-initialized-in-bss"); |
| 326 | if (Args.hasArg(options::OPT_dA) || Args.hasArg(options::OPT_fverbose_asm)) |
| 327 | CmdArgs.push_back("--asm-verbose"); |
| 328 | if (Args.hasArg(options::OPT_fdebug_pass_structure)) |
| 329 | CmdArgs.push_back("--debug-pass=Structure"); |
| 330 | if (Args.hasArg(options::OPT_fdebug_pass_arguments)) |
| 331 | CmdArgs.push_back("--debug-pass=Arguments"); |
| 332 | // FIXME: set --inline-threshhold=50 if (optimize_size || optimize |
| 333 | // < 3) |
| 334 | if (Args.hasFlag(options::OPT_funwind_tables, |
| 335 | options::OPT_fno_unwind_tables, |
| 336 | (getToolChain().IsUnwindTablesDefault() && |
| 337 | !Args.hasArg(options::OPT_mkernel)))) |
| 338 | CmdArgs.push_back("--unwind-tables=1"); |
| 339 | else |
| 340 | CmdArgs.push_back("--unwind-tables=0"); |
| 341 | if (!Args.hasFlag(options::OPT_mred_zone, |
| 342 | options::OPT_mno_red_zone, |
| 343 | true) || |
| 344 | Args.hasArg(options::OPT_mkernel) || |
| 345 | Args.hasArg(options::OPT_fapple_kext)) |
| 346 | CmdArgs.push_back("--disable-red-zone"); |
| 347 | if (Args.hasFlag(options::OPT_msoft_float, |
| 348 | options::OPT_mno_soft_float, |
| 349 | false)) |
Devang Patel | acebb39 | 2009-06-05 22:05:48 +0000 | [diff] [blame] | 350 | CmdArgs.push_back("--no-implicit-float"); |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 351 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 352 | // FIXME: Handle -mtune=. |
| 353 | (void) Args.hasArg(options::OPT_mtune_EQ); |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 354 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 355 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { |
Daniel Dunbar | d8fc0f2 | 2009-05-22 00:38:15 +0000 | [diff] [blame] | 356 | // FIXME: We may need some translation here from the options gcc takes to |
| 357 | // names the LLVM backend understand? |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 358 | CmdArgs.push_back("-mcpu"); |
| 359 | CmdArgs.push_back(A->getValue(Args)); |
| 360 | } else { |
| 361 | // Select default CPU. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 362 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 363 | // FIXME: Need target hooks. |
| 364 | if (memcmp(getToolChain().getOS().c_str(), "darwin", 6) == 0) { |
| 365 | if (getToolChain().getArchName() == "x86_64") |
| 366 | CmdArgs.push_back("--mcpu=core2"); |
| 367 | else if (getToolChain().getArchName() == "i386") |
Daniel Dunbar | 500aec4 | 2009-05-06 04:58:14 +0000 | [diff] [blame] | 368 | CmdArgs.push_back("--mcpu=yonah"); |
| 369 | } else { |
| 370 | if (getToolChain().getArchName() == "x86_64") |
| 371 | CmdArgs.push_back("--mcpu=x86-64"); |
| 372 | else if (getToolChain().getArchName() == "i386") |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 373 | CmdArgs.push_back("--mcpu=pentium4"); |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 374 | } |
| 375 | } |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 376 | |
Benjamin Kramer | 8e9ef0d | 2009-08-05 14:30:52 +0000 | [diff] [blame] | 377 | if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) { |
| 378 | CmdArgs.push_back("-code-model"); |
| 379 | CmdArgs.push_back(A->getValue(Args)); |
| 380 | } |
| 381 | |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 382 | // FIXME: Use iterator. |
| 383 | for (ArgList::const_iterator |
| 384 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 385 | const Arg *A = *it; |
| 386 | if (A->getOption().matches(options::OPT_m_x86_Features_Group)) { |
Daniel Dunbar | 5b750fe | 2009-09-09 22:32:34 +0000 | [diff] [blame] | 387 | llvm::StringRef Name = A->getOption().getName(); |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 388 | |
| 389 | // Skip over "-m". |
Daniel Dunbar | 5b750fe | 2009-09-09 22:32:34 +0000 | [diff] [blame] | 390 | assert(Name.startswith("-m") && "Invalid feature name."); |
| 391 | Name = Name.substr(2); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 392 | |
Daniel Dunbar | 5b750fe | 2009-09-09 22:32:34 +0000 | [diff] [blame] | 393 | bool IsNegative = Name.startswith("no-"); |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 394 | if (IsNegative) |
Daniel Dunbar | 5b750fe | 2009-09-09 22:32:34 +0000 | [diff] [blame] | 395 | Name = Name.substr(3); |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 396 | |
| 397 | A->claim(); |
| 398 | CmdArgs.push_back("-target-feature"); |
Daniel Dunbar | 5b750fe | 2009-09-09 22:32:34 +0000 | [diff] [blame] | 399 | CmdArgs.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name)); |
Daniel Dunbar | 868bd0a | 2009-05-06 03:16:41 +0000 | [diff] [blame] | 400 | } |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | if (Args.hasFlag(options::OPT_fmath_errno, |
| 404 | options::OPT_fno_math_errno, |
| 405 | getToolChain().IsMathErrnoDefault())) |
| 406 | CmdArgs.push_back("--fmath-errno=1"); |
| 407 | else |
| 408 | CmdArgs.push_back("--fmath-errno=0"); |
| 409 | |
| 410 | if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) { |
| 411 | CmdArgs.push_back("--limit-float-precision"); |
| 412 | CmdArgs.push_back(A->getValue(Args)); |
| 413 | } |
| 414 | |
| 415 | // FIXME: Add --stack-protector-buffer-size=<xxx> on |
| 416 | // -fstack-protect. |
| 417 | |
| 418 | Arg *Unsupported; |
| 419 | if ((Unsupported = Args.getLastArg(options::OPT_MG)) || |
Daniel Dunbar | 95a0da7 | 2009-05-13 19:05:04 +0000 | [diff] [blame] | 420 | (Unsupported = Args.getLastArg(options::OPT_MQ)) || |
| 421 | (Unsupported = Args.getLastArg(options::OPT_iframework))) |
Daniel Dunbar | e027a4b | 2009-05-22 19:02:20 +0000 | [diff] [blame] | 422 | D.Diag(clang::diag::err_drv_clang_unsupported) |
Daniel Dunbar | bc85be8 | 2009-04-29 18:32:25 +0000 | [diff] [blame] | 423 | << Unsupported->getOption().getName(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 424 | |
| 425 | Args.AddAllArgs(CmdArgs, options::OPT_v); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 426 | Args.AddLastArg(CmdArgs, options::OPT_P); |
Daniel Dunbar | 2ac9fc2 | 2009-04-07 21:42:00 +0000 | [diff] [blame] | 427 | Args.AddLastArg(CmdArgs, options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 428 | Args.AddLastArg(CmdArgs, options::OPT_miphoneos_version_min_EQ); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 429 | Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 430 | |
| 431 | // Special case debug options to only pass -g to clang. This is |
| 432 | // wrong. |
| 433 | if (Args.hasArg(options::OPT_g_Group)) |
| 434 | CmdArgs.push_back("-g"); |
| 435 | |
| 436 | Args.AddLastArg(CmdArgs, options::OPT_nostdinc); |
| 437 | |
Daniel Dunbar | 2ac9fc2 | 2009-04-07 21:42:00 +0000 | [diff] [blame] | 438 | Args.AddLastArg(CmdArgs, options::OPT_isysroot); |
| 439 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 440 | // Add preprocessing options like -I, -D, etc. if we are using the |
| 441 | // preprocessor. |
| 442 | // |
| 443 | // FIXME: Support -fpreprocessed |
| 444 | types::ID InputType = Inputs[0].getType(); |
| 445 | if (types::getPreprocessedType(InputType) != types::TY_INVALID) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 446 | AddPreprocessingOptions(D, Args, CmdArgs, Output, Inputs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 447 | |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 448 | // Manually translate -O to -O1 and -O4 to -O3; let clang reject |
| 449 | // others. |
| 450 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 451 | if (A->getOption().getId() == options::OPT_O4) |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 452 | CmdArgs.push_back("-O3"); |
| 453 | else if (A->getValue(Args)[0] == '\0') |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 454 | CmdArgs.push_back("-O1"); |
| 455 | else |
Daniel Dunbar | 5697aa0 | 2009-03-18 23:39:35 +0000 | [diff] [blame] | 456 | A->render(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Daniel Dunbar | 06ef3c3 | 2009-04-16 03:44:10 +0000 | [diff] [blame] | 459 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 460 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 461 | |
| 462 | // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi} |
| 463 | // (-ansi is equivalent to -std=c89). |
| 464 | // |
| 465 | // If a std is supplied, only add -trigraphs if it follows the |
| 466 | // option. |
| 467 | if (Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { |
| 468 | if (Std->getOption().matches(options::OPT_ansi)) |
| 469 | CmdArgs.push_back("-std=c89"); |
| 470 | else |
| 471 | Std->render(Args, CmdArgs); |
| 472 | |
| 473 | if (Arg *A = Args.getLastArg(options::OPT_trigraphs)) |
| 474 | if (A->getIndex() > Std->getIndex()) |
| 475 | A->render(Args, CmdArgs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 476 | } else { |
| 477 | // Honor -std-default. |
| 478 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, |
| 479 | "-std=", /*Joined=*/true); |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 480 | Args.AddLastArg(CmdArgs, options::OPT_trigraphs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 481 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 482 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 483 | if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) { |
| 484 | CmdArgs.push_back("-ftemplate-depth"); |
| 485 | CmdArgs.push_back(A->getValue(Args)); |
| 486 | } |
| 487 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 488 | if (Args.hasArg(options::OPT__relocatable_pch, true)) |
| 489 | CmdArgs.push_back("--relocatable-pch"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 490 | |
David Chisnall | 8a5a9aa | 2009-08-31 16:41:57 +0000 | [diff] [blame] | 491 | if (Arg *A = Args.getLastArg(options::OPT_fconstant_string_class_EQ)) { |
| 492 | CmdArgs.push_back("-fconstant-string-class"); |
| 493 | CmdArgs.push_back(A->getValue(Args)); |
| 494 | } |
| 495 | |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 496 | // Forward -f options which we can pass directly. |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 497 | Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 498 | Args.AddLastArg(CmdArgs, options::OPT_ffreestanding); |
| 499 | Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); |
| 500 | Args.AddLastArg(CmdArgs, options::OPT_fgnu_runtime); |
| 501 | Args.AddLastArg(CmdArgs, options::OPT_flax_vector_conversions); |
Douglas Gregor | fffd93f | 2009-05-01 21:53:04 +0000 | [diff] [blame] | 502 | Args.AddLastArg(CmdArgs, options::OPT_fmessage_length_EQ); |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 503 | Args.AddLastArg(CmdArgs, options::OPT_fms_extensions); |
| 504 | Args.AddLastArg(CmdArgs, options::OPT_fnext_runtime); |
| 505 | Args.AddLastArg(CmdArgs, options::OPT_fno_caret_diagnostics); |
| 506 | Args.AddLastArg(CmdArgs, options::OPT_fno_show_column); |
| 507 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc_only); |
| 508 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc); |
Fariborz Jahanian | 34e6577 | 2009-05-22 20:17:16 +0000 | [diff] [blame] | 509 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch); |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 510 | // FIXME: Should we remove this? |
| 511 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_nonfragile_abi); |
Daniel Dunbar | d6884a0 | 2009-05-04 05:16:21 +0000 | [diff] [blame] | 512 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_tight_layout); |
Chris Lattner | 182e092 | 2009-04-21 05:34:31 +0000 | [diff] [blame] | 513 | Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info); |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 514 | Args.AddLastArg(CmdArgs, options::OPT_ftime_report); |
| 515 | Args.AddLastArg(CmdArgs, options::OPT_ftrapv); |
| 516 | Args.AddLastArg(CmdArgs, options::OPT_fvisibility_EQ); |
| 517 | Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 518 | |
Daniel Dunbar | 5345c39 | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 519 | Args.AddLastArg(CmdArgs, options::OPT_pthread); |
| 520 | |
Bill Wendling | 45483f7 | 2009-06-28 07:36:13 +0000 | [diff] [blame] | 521 | // Forward stack protector flags. |
| 522 | if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector, |
| 523 | options::OPT_fstack_protector_all, |
| 524 | options::OPT_fstack_protector)) { |
| 525 | if (A->getOption().matches(options::OPT_fno_stack_protector)) |
| 526 | CmdArgs.push_back("--stack-protector=0"); |
| 527 | else if (A->getOption().matches(options::OPT_fstack_protector)) |
| 528 | CmdArgs.push_back("--stack-protector=1"); |
| 529 | else |
| 530 | CmdArgs.push_back("--stack-protector=2"); |
| 531 | } |
| 532 | |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 533 | // Forward -f options with positive and negative forms; we translate |
| 534 | // these by hand. |
| 535 | |
| 536 | // -fbuiltin is default, only pass non-default. |
| 537 | if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin)) |
| 538 | CmdArgs.push_back("-fbuiltin=0"); |
| 539 | |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 540 | // -fblocks default varies depending on platform and language; only |
| 541 | // pass if specified. |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 542 | if (Arg *A = Args.getLastArg(options::OPT_fblocks, options::OPT_fno_blocks)) { |
| 543 | if (A->getOption().matches(options::OPT_fblocks)) |
| 544 | CmdArgs.push_back("-fblocks"); |
| 545 | else |
| 546 | CmdArgs.push_back("-fblocks=0"); |
| 547 | } |
| 548 | |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 549 | // -fexceptions default varies depending on platform and language; only |
| 550 | // pass if specified. |
| 551 | if (Arg *A = Args.getLastArg(options::OPT_fexceptions, |
| 552 | options::OPT_fno_exceptions)) { |
| 553 | if (A->getOption().matches(options::OPT_fexceptions)) |
| 554 | CmdArgs.push_back("-fexceptions"); |
| 555 | else |
| 556 | CmdArgs.push_back("-fexceptions=0"); |
| 557 | } |
| 558 | |
| 559 | // -frtti is default, only pass non-default. |
| 560 | if (!Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti)) |
| 561 | CmdArgs.push_back("-frtti=0"); |
| 562 | |
Eli Friedman | 5a77973 | 2009-06-05 07:21:14 +0000 | [diff] [blame] | 563 | // -fsigned-char/-funsigned-char default varies depending on platform; only |
| 564 | // pass if specified. |
| 565 | if (Arg *A = Args.getLastArg(options::OPT_fsigned_char, |
| 566 | options::OPT_funsigned_char)) { |
| 567 | if (A->getOption().matches(options::OPT_fsigned_char)) |
| 568 | CmdArgs.push_back("-fsigned-char"); |
| 569 | else |
| 570 | CmdArgs.push_back("-fsigned-char=0"); |
| 571 | } |
| 572 | |
Daniel Dunbar | 82d0068 | 2009-04-07 23:51:44 +0000 | [diff] [blame] | 573 | // -fno-pascal-strings is default, only pass non-default. If the |
| 574 | // -tool chain happened to translate to -mpascal-strings, we want to |
| 575 | // -back translate here. |
| 576 | // |
| 577 | // FIXME: This is gross; that translation should be pulled from the |
| 578 | // tool chain. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 579 | if (Args.hasFlag(options::OPT_fpascal_strings, |
Daniel Dunbar | 82d0068 | 2009-04-07 23:51:44 +0000 | [diff] [blame] | 580 | options::OPT_fno_pascal_strings, |
| 581 | false) || |
| 582 | Args.hasFlag(options::OPT_mpascal_strings, |
| 583 | options::OPT_mno_pascal_strings, |
| 584 | false)) |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 585 | CmdArgs.push_back("-fpascal-strings"); |
| 586 | |
| 587 | // -fcommon is default, only pass non-default. |
| 588 | if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common)) |
| 589 | CmdArgs.push_back("-fno-common"); |
| 590 | |
Daniel Dunbar | 70d3c92 | 2009-04-15 02:37:43 +0000 | [diff] [blame] | 591 | // -fsigned-bitfields is default, and clang doesn't yet support |
| 592 | // --funsigned-bitfields. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 593 | if (!Args.hasFlag(options::OPT_fsigned_bitfields, |
Daniel Dunbar | 70d3c92 | 2009-04-15 02:37:43 +0000 | [diff] [blame] | 594 | options::OPT_funsigned_bitfields)) |
| 595 | D.Diag(clang::diag::warn_drv_clang_unsupported) |
| 596 | << Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args); |
| 597 | |
Daniel Dunbar | 49138fc | 2009-04-19 21:09:34 +0000 | [diff] [blame] | 598 | // -fdiagnostics-fixit-info is default, only pass non-default. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 599 | if (!Args.hasFlag(options::OPT_fdiagnostics_fixit_info, |
Daniel Dunbar | 49138fc | 2009-04-19 21:09:34 +0000 | [diff] [blame] | 600 | options::OPT_fno_diagnostics_fixit_info)) |
| 601 | CmdArgs.push_back("-fno-diagnostics-fixit-info"); |
| 602 | |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 603 | // Enable -fdiagnostics-show-option by default. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 604 | if (Args.hasFlag(options::OPT_fdiagnostics_show_option, |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 605 | options::OPT_fno_diagnostics_show_option)) |
| 606 | CmdArgs.push_back("-fdiagnostics-show-option"); |
Torok Edwin | a46c71a | 2009-06-04 07:27:53 +0000 | [diff] [blame] | 607 | if (!Args.hasFlag(options::OPT_fcolor_diagnostics, |
Daniel Dunbar | 75eb1d6 | 2009-06-08 21:13:54 +0000 | [diff] [blame] | 608 | options::OPT_fno_color_diagnostics)) |
Torok Edwin | a46c71a | 2009-06-04 07:27:53 +0000 | [diff] [blame] | 609 | CmdArgs.push_back("-fno-color-diagnostics"); |
Daniel Dunbar | 75eb1d6 | 2009-06-08 21:13:54 +0000 | [diff] [blame] | 610 | if (!Args.hasFlag(options::OPT_fshow_source_location, |
| 611 | options::OPT_fno_show_source_location)) |
| 612 | CmdArgs.push_back("-fno-show-source-location"); |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 613 | |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 614 | // -fdollars-in-identifiers default varies depending on platform and |
| 615 | // language; only pass if specified. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 616 | if (Arg *A = Args.getLastArg(options::OPT_fdollars_in_identifiers, |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 617 | options::OPT_fno_dollars_in_identifiers)) { |
| 618 | if (A->getOption().matches(options::OPT_fdollars_in_identifiers)) |
| 619 | CmdArgs.push_back("-fdollars-in-identifiers=1"); |
| 620 | else |
| 621 | CmdArgs.push_back("-fdollars-in-identifiers=0"); |
| 622 | } |
| 623 | |
Daniel Dunbar | e027a4b | 2009-05-22 19:02:20 +0000 | [diff] [blame] | 624 | // -funit-at-a-time is default, and we don't support -fno-unit-at-a-time for |
| 625 | // practical purposes. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 626 | if (Arg *A = Args.getLastArg(options::OPT_funit_at_a_time, |
Daniel Dunbar | e027a4b | 2009-05-22 19:02:20 +0000 | [diff] [blame] | 627 | options::OPT_fno_unit_at_a_time)) { |
| 628 | if (A->getOption().matches(options::OPT_fno_unit_at_a_time)) |
| 629 | D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args); |
| 630 | } |
Eli Friedman | ceb5c5b | 2009-07-14 21:58:17 +0000 | [diff] [blame] | 631 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 632 | if (Arg *A = Args.getLastArg(options::OPT_traditional, |
Eli Friedman | ceb5c5b | 2009-07-14 21:58:17 +0000 | [diff] [blame] | 633 | options::OPT_traditional_cpp)) |
| 634 | D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args); |
| 635 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 636 | Args.AddLastArg(CmdArgs, options::OPT_dM); |
Chris Lattner | d82df3a | 2009-04-12 01:56:53 +0000 | [diff] [blame] | 637 | Args.AddLastArg(CmdArgs, options::OPT_dD); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 638 | |
| 639 | Args.AddAllArgValues(CmdArgs, options::OPT_Xclang); |
Daniel Dunbar | e528028 | 2009-06-03 16:16:27 +0000 | [diff] [blame] | 640 | Args.AddAllArgValues(CmdArgs, options::OPT_mllvm); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 641 | |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 642 | if (Output.getType() == types::TY_Dependencies) { |
| 643 | // Handled with other dependency code. |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 644 | } else if (Output.isPipe()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 645 | CmdArgs.push_back("-o"); |
| 646 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 647 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 648 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 649 | CmdArgs.push_back(Output.getFilename()); |
| 650 | } else { |
| 651 | assert(Output.isNothing() && "Invalid output."); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 654 | for (InputInfoList::const_iterator |
| 655 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 656 | const InputInfo &II = *it; |
| 657 | CmdArgs.push_back("-x"); |
| 658 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 659 | if (II.isPipe()) |
| 660 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 661 | else if (II.isFilename()) |
| 662 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 663 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 664 | II.getInputArg().renderAsInput(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 665 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 666 | |
| 667 | const char *Exec = |
Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 668 | Args.MakeArgString(getToolChain().GetProgramPath(C, "clang-cc").c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 669 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 670 | |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 671 | // Explicitly warn that these options are unsupported, even though |
| 672 | // we are allowing compilation to continue. |
| 673 | // FIXME: Use iterator. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 674 | for (ArgList::const_iterator |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 675 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 676 | const Arg *A = *it; |
| 677 | if (A->getOption().matches(options::OPT_pg)) { |
| 678 | A->claim(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 679 | D.Diag(clang::diag::warn_drv_clang_unsupported) |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 680 | << A->getAsString(Args); |
| 681 | } |
| 682 | } |
| 683 | |
Daniel Dunbar | 68fb469 | 2009-04-03 20:51:31 +0000 | [diff] [blame] | 684 | // Claim some arguments which clang supports automatically. |
| 685 | |
| 686 | // -fpch-preprocess is used with gcc to add a special marker in the |
| 687 | // -output to include the PCH file. Clang's PTH solution is |
| 688 | // -completely transparent, so we do not need to deal with it at |
| 689 | // -all. |
| 690 | Args.ClaimAllArgs(options::OPT_fpch_preprocess); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 691 | |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 692 | // Claim some arguments which clang doesn't support, but we don't |
| 693 | // care to warn the user about. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 694 | |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 695 | // FIXME: Use iterator. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 696 | for (ArgList::const_iterator |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 697 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 698 | const Arg *A = *it; |
Daniel Dunbar | 06ef3c3 | 2009-04-16 03:44:10 +0000 | [diff] [blame] | 699 | if (A->getOption().matches(options::OPT_clang_ignored_f_Group) || |
Daniel Dunbar | 16fd3a9 | 2009-04-07 02:59:27 +0000 | [diff] [blame] | 700 | A->getOption().matches(options::OPT_clang_ignored_m_Group)) |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 701 | A->claim(); |
| 702 | } |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 703 | } |
| 704 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 705 | void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, |
| 706 | Job &Dest, |
| 707 | const InputInfo &Output, |
| 708 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 709 | const ArgList &Args, |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 710 | const char *LinkingOutput) const { |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 711 | const Driver &D = getToolChain().getHost().getDriver(); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 712 | ArgStringList CmdArgs; |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 713 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 714 | for (ArgList::const_iterator |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 715 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 716 | Arg *A = *it; |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 717 | if (A->getOption().hasForwardToGCC()) { |
| 718 | // It is unfortunate that we have to claim here, as this means |
| 719 | // we will basically never report anything interesting for |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 720 | // platforms using a generic gcc, even if we are just using gcc |
| 721 | // to get to the assembler. |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 722 | A->claim(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 723 | A->render(Args, CmdArgs); |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 724 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 725 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 726 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 727 | RenderExtraToolArgs(CmdArgs); |
| 728 | |
| 729 | // If using a driver driver, force the arch. |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 730 | const std::string &Arch = getToolChain().getArchName(); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 731 | if (getToolChain().getHost().useDriverDriver()) { |
| 732 | CmdArgs.push_back("-arch"); |
Daniel Dunbar | bf54a06 | 2009-04-01 20:33:11 +0000 | [diff] [blame] | 733 | |
| 734 | // FIXME: Remove these special cases. |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 735 | if (Arch == "powerpc") |
| 736 | CmdArgs.push_back("ppc"); |
| 737 | else if (Arch == "powerpc64") |
| 738 | CmdArgs.push_back("ppc64"); |
| 739 | else |
| 740 | CmdArgs.push_back(Args.MakeArgString(Arch.c_str())); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 741 | } |
| 742 | |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 743 | // Try to force gcc to match the tool chain we want, if we recognize |
| 744 | // the arch. |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 745 | // |
| 746 | // FIXME: The triple class should directly provide the information we want |
| 747 | // here. |
| 748 | if (Arch == "i386" || Arch == "powerpc") |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 749 | CmdArgs.push_back("-m32"); |
Daniel Dunbar | 7cfe31a | 2009-05-22 02:21:04 +0000 | [diff] [blame] | 750 | else if (Arch == "x86_64" || Arch == "powerpc64") |
Daniel Dunbar | 6ecc7a9 | 2009-05-02 21:41:52 +0000 | [diff] [blame] | 751 | CmdArgs.push_back("-m64"); |
| 752 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 753 | if (Output.isPipe()) { |
| 754 | CmdArgs.push_back("-o"); |
| 755 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 756 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 757 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 758 | CmdArgs.push_back(Output.getFilename()); |
| 759 | } else { |
| 760 | assert(Output.isNothing() && "Unexpected output"); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 761 | CmdArgs.push_back("-fsyntax-only"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 762 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 763 | |
| 764 | |
| 765 | // Only pass -x if gcc will understand it; otherwise hope gcc |
| 766 | // understands the suffix correctly. The main use case this would go |
| 767 | // wrong in is for linker inputs if they happened to have an odd |
| 768 | // suffix; really the only way to get this to happen is a command |
| 769 | // like '-x foobar a.c' which will treat a.c like a linker input. |
| 770 | // |
| 771 | // FIXME: For the linker case specifically, can we safely convert |
| 772 | // inputs into '-Wl,' options? |
| 773 | for (InputInfoList::const_iterator |
| 774 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 775 | const InputInfo &II = *it; |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 776 | |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 777 | // Don't try to pass LLVM or AST inputs to a generic gcc. |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 778 | if (II.getType() == types::TY_LLVMBC) |
| 779 | D.Diag(clang::diag::err_drv_no_linker_llvm_support) |
| 780 | << getToolChain().getTripleString().c_str(); |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 781 | else if (II.getType() == types::TY_AST) |
| 782 | D.Diag(clang::diag::err_drv_no_ast_support) |
| 783 | << getToolChain().getTripleString().c_str(); |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 784 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 785 | if (types::canTypeBeUserSpecified(II.getType())) { |
| 786 | CmdArgs.push_back("-x"); |
| 787 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 788 | } |
| 789 | |
| 790 | if (II.isPipe()) |
| 791 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 792 | else if (II.isFilename()) |
| 793 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 794 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 795 | // Don't render as input, we need gcc to do the translations. |
| 796 | II.getInputArg().render(Args, CmdArgs); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 797 | } |
| 798 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 799 | const char *GCCName = |
Daniel Dunbar | 78d8a08 | 2009-04-01 23:34:41 +0000 | [diff] [blame] | 800 | getToolChain().getHost().getDriver().CCCGenericGCCName.c_str(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 801 | const char *Exec = |
Daniel Dunbar | 78d8a08 | 2009-04-01 23:34:41 +0000 | [diff] [blame] | 802 | Args.MakeArgString(getToolChain().GetProgramPath(C, GCCName).c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 803 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 804 | } |
| 805 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 806 | void gcc::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 807 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 810 | void gcc::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 811 | // The type is good enough. |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 814 | void gcc::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 815 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 816 | } |
| 817 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 818 | void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 819 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 820 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 821 | |
| 822 | void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 823 | // The types are (hopefully) good enough. |
| 824 | } |
| 825 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 826 | const char *darwin::CC1::getCC1Name(types::ID Type) const { |
| 827 | switch (Type) { |
| 828 | default: |
| 829 | assert(0 && "Unexpected type for Darwin CC1 tool."); |
| 830 | case types::TY_Asm: |
| 831 | case types::TY_C: case types::TY_CHeader: |
| 832 | case types::TY_PP_C: case types::TY_PP_CHeader: |
| 833 | return "cc1"; |
| 834 | case types::TY_ObjC: case types::TY_ObjCHeader: |
| 835 | case types::TY_PP_ObjC: case types::TY_PP_ObjCHeader: |
| 836 | return "cc1obj"; |
| 837 | case types::TY_CXX: case types::TY_CXXHeader: |
| 838 | case types::TY_PP_CXX: case types::TY_PP_CXXHeader: |
| 839 | return "cc1plus"; |
| 840 | case types::TY_ObjCXX: case types::TY_ObjCXXHeader: |
| 841 | case types::TY_PP_ObjCXX: case types::TY_PP_ObjCXXHeader: |
| 842 | return "cc1objplus"; |
| 843 | } |
| 844 | } |
| 845 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 846 | const char *darwin::CC1::getBaseInputName(const ArgList &Args, |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 847 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 848 | llvm::sys::Path P(Inputs[0].getBaseInput()); |
| 849 | return Args.MakeArgString(P.getLast().c_str()); |
| 850 | } |
| 851 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 852 | const char *darwin::CC1::getBaseInputStem(const ArgList &Args, |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 853 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 854 | const char *Str = getBaseInputName(Args, Inputs); |
| 855 | |
| 856 | if (const char *End = strchr(Str, '.')) |
| 857 | return Args.MakeArgString(std::string(Str, End).c_str()); |
| 858 | |
| 859 | return Str; |
| 860 | } |
| 861 | |
| 862 | const char * |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 863 | darwin::CC1::getDependencyFileName(const ArgList &Args, |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 864 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 865 | // FIXME: Think about this more. |
| 866 | std::string Res; |
| 867 | |
| 868 | if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) { |
| 869 | std::string Str(OutputOpt->getValue(Args)); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 870 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 871 | Res = Str.substr(0, Str.rfind('.')); |
| 872 | } else |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 873 | Res = darwin::CC1::getBaseInputStem(Args, Inputs); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 874 | |
| 875 | return Args.MakeArgString((Res + ".d").c_str()); |
| 876 | } |
| 877 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 878 | void darwin::CC1::AddCC1Args(const ArgList &Args, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 879 | ArgStringList &CmdArgs) const { |
| 880 | // Derived from cc1 spec. |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 881 | if (!Args.hasArg(options::OPT_mkernel) && !Args.hasArg(options::OPT_static) && |
| 882 | !Args.hasArg(options::OPT_mdynamic_no_pic)) |
| 883 | CmdArgs.push_back("-fPIC"); |
| 884 | |
| 885 | // gcc has some code here to deal with when no -mmacosx-version-min |
| 886 | // and no -miphoneos-version-min is present, but this never happens |
| 887 | // due to tool chain specific argument translation. |
| 888 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 889 | if (Args.hasArg(options::OPT_g_Flag) && |
| 890 | !Args.hasArg(options::OPT_fno_eliminate_unused_debug_symbols)) |
| 891 | CmdArgs.push_back("-feliminate-unused-debug-symbols"); |
| 892 | } |
| 893 | |
| 894 | void darwin::CC1::AddCC1OptionsArgs(const ArgList &Args, ArgStringList &CmdArgs, |
| 895 | const InputInfoList &Inputs, |
| 896 | const ArgStringList &OutputArgs) const { |
| 897 | const Driver &D = getToolChain().getHost().getDriver(); |
| 898 | |
| 899 | // Derived from cc1_options spec. |
| 900 | if (Args.hasArg(options::OPT_fast) || |
| 901 | Args.hasArg(options::OPT_fastf) || |
| 902 | Args.hasArg(options::OPT_fastcp)) |
| 903 | CmdArgs.push_back("-O3"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 904 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 905 | if (Arg *A = Args.getLastArg(options::OPT_pg)) |
| 906 | if (Args.hasArg(options::OPT_fomit_frame_pointer)) |
| 907 | D.Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 908 | << A->getAsString(Args) << "-fomit-frame-pointer"; |
| 909 | |
| 910 | AddCC1Args(Args, CmdArgs); |
| 911 | |
| 912 | if (!Args.hasArg(options::OPT_Q)) |
| 913 | CmdArgs.push_back("-quiet"); |
| 914 | |
| 915 | CmdArgs.push_back("-dumpbase"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 916 | CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 917 | |
| 918 | Args.AddAllArgs(CmdArgs, options::OPT_d_Group); |
| 919 | |
| 920 | Args.AddAllArgs(CmdArgs, options::OPT_m_Group); |
| 921 | Args.AddAllArgs(CmdArgs, options::OPT_a_Group); |
| 922 | |
| 923 | // FIXME: The goal is to use the user provided -o if that is our |
| 924 | // final output, otherwise to drive from the original input |
| 925 | // name. Find a clean way to go about this. |
| 926 | if ((Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) && |
| 927 | Args.hasArg(options::OPT_o)) { |
| 928 | Arg *OutputOpt = Args.getLastArg(options::OPT_o); |
| 929 | CmdArgs.push_back("-auxbase-strip"); |
| 930 | CmdArgs.push_back(OutputOpt->getValue(Args)); |
| 931 | } else { |
| 932 | CmdArgs.push_back("-auxbase"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 933 | CmdArgs.push_back(darwin::CC1::getBaseInputStem(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | Args.AddAllArgs(CmdArgs, options::OPT_g_Group); |
| 937 | |
| 938 | Args.AddAllArgs(CmdArgs, options::OPT_O); |
| 939 | // FIXME: -Wall is getting some special treatment. Investigate. |
| 940 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group); |
| 941 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 942 | Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 943 | options::OPT_trigraphs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 944 | if (!Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { |
| 945 | // Honor -std-default. |
| 946 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, |
| 947 | "-std=", /*Joined=*/true); |
| 948 | } |
| 949 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 950 | if (Args.hasArg(options::OPT_v)) |
| 951 | CmdArgs.push_back("-version"); |
| 952 | if (Args.hasArg(options::OPT_pg)) |
| 953 | CmdArgs.push_back("-p"); |
| 954 | Args.AddLastArg(CmdArgs, options::OPT_p); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 955 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 956 | // The driver treats -fsyntax-only specially. |
| 957 | Args.AddAllArgs(CmdArgs, options::OPT_f_Group, options::OPT_fsyntax_only); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 958 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 959 | Args.AddAllArgs(CmdArgs, options::OPT_undef); |
| 960 | if (Args.hasArg(options::OPT_Qn)) |
| 961 | CmdArgs.push_back("-fno-ident"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 962 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 963 | // FIXME: This isn't correct. |
| 964 | //Args.AddLastArg(CmdArgs, options::OPT__help) |
| 965 | //Args.AddLastArg(CmdArgs, options::OPT__targetHelp) |
| 966 | |
| 967 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 968 | |
| 969 | // FIXME: Still don't get what is happening here. Investigate. |
| 970 | Args.AddAllArgs(CmdArgs, options::OPT__param); |
| 971 | |
| 972 | if (Args.hasArg(options::OPT_fmudflap) || |
| 973 | Args.hasArg(options::OPT_fmudflapth)) { |
| 974 | CmdArgs.push_back("-fno-builtin"); |
| 975 | CmdArgs.push_back("-fno-merge-constants"); |
| 976 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 977 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 978 | if (Args.hasArg(options::OPT_coverage)) { |
| 979 | CmdArgs.push_back("-fprofile-arcs"); |
| 980 | CmdArgs.push_back("-ftest-coverage"); |
| 981 | } |
| 982 | |
| 983 | if (types::isCXX(Inputs[0].getType())) |
| 984 | CmdArgs.push_back("-D__private_extern__=extern"); |
| 985 | } |
| 986 | |
| 987 | void darwin::CC1::AddCPPOptionsArgs(const ArgList &Args, ArgStringList &CmdArgs, |
| 988 | const InputInfoList &Inputs, |
| 989 | const ArgStringList &OutputArgs) const { |
| 990 | // Derived from cpp_options |
| 991 | AddCPPUniqueOptionsArgs(Args, CmdArgs, Inputs); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 992 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 993 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 994 | |
| 995 | AddCC1Args(Args, CmdArgs); |
| 996 | |
| 997 | // NOTE: The code below has some commonality with cpp_options, but |
| 998 | // in classic gcc style ends up sending things in different |
| 999 | // orders. This may be a good merge candidate once we drop pedantic |
| 1000 | // compatibility. |
| 1001 | |
| 1002 | Args.AddAllArgs(CmdArgs, options::OPT_m_Group); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1003 | Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1004 | options::OPT_trigraphs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 1005 | if (!Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { |
| 1006 | // Honor -std-default. |
| 1007 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, |
| 1008 | "-std=", /*Joined=*/true); |
| 1009 | } |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1010 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group); |
| 1011 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1012 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1013 | // The driver treats -fsyntax-only specially. |
| 1014 | Args.AddAllArgs(CmdArgs, options::OPT_f_Group, options::OPT_fsyntax_only); |
| 1015 | |
| 1016 | if (Args.hasArg(options::OPT_g_Group) && !Args.hasArg(options::OPT_g0) && |
| 1017 | !Args.hasArg(options::OPT_fno_working_directory)) |
| 1018 | CmdArgs.push_back("-fworking-directory"); |
| 1019 | |
| 1020 | Args.AddAllArgs(CmdArgs, options::OPT_O); |
| 1021 | Args.AddAllArgs(CmdArgs, options::OPT_undef); |
| 1022 | if (Args.hasArg(options::OPT_save_temps)) |
| 1023 | CmdArgs.push_back("-fpch-preprocess"); |
| 1024 | } |
| 1025 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1026 | void darwin::CC1::AddCPPUniqueOptionsArgs(const ArgList &Args, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1027 | ArgStringList &CmdArgs, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1028 | const InputInfoList &Inputs) const { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1029 | const Driver &D = getToolChain().getHost().getDriver(); |
| 1030 | |
| 1031 | // Derived from cpp_unique_options. |
| 1032 | Arg *A; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1033 | if ((A = Args.getLastArg(options::OPT_C)) || |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1034 | (A = Args.getLastArg(options::OPT_CC))) { |
| 1035 | if (!Args.hasArg(options::OPT_E)) |
| 1036 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 1037 | << A->getAsString(Args) << "-E"; |
| 1038 | } |
| 1039 | if (!Args.hasArg(options::OPT_Q)) |
| 1040 | CmdArgs.push_back("-quiet"); |
| 1041 | Args.AddAllArgs(CmdArgs, options::OPT_nostdinc); |
| 1042 | Args.AddLastArg(CmdArgs, options::OPT_v); |
| 1043 | Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F); |
| 1044 | Args.AddLastArg(CmdArgs, options::OPT_P); |
| 1045 | |
| 1046 | // FIXME: Handle %I properly. |
| 1047 | if (getToolChain().getArchName() == "x86_64") { |
| 1048 | CmdArgs.push_back("-imultilib"); |
| 1049 | CmdArgs.push_back("x86_64"); |
| 1050 | } |
| 1051 | |
| 1052 | if (Args.hasArg(options::OPT_MD)) { |
| 1053 | CmdArgs.push_back("-MD"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 1054 | CmdArgs.push_back(darwin::CC1::getDependencyFileName(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | if (Args.hasArg(options::OPT_MMD)) { |
| 1058 | CmdArgs.push_back("-MMD"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 1059 | CmdArgs.push_back(darwin::CC1::getDependencyFileName(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | Args.AddLastArg(CmdArgs, options::OPT_M); |
| 1063 | Args.AddLastArg(CmdArgs, options::OPT_MM); |
| 1064 | Args.AddAllArgs(CmdArgs, options::OPT_MF); |
| 1065 | Args.AddLastArg(CmdArgs, options::OPT_MG); |
| 1066 | Args.AddLastArg(CmdArgs, options::OPT_MP); |
| 1067 | Args.AddAllArgs(CmdArgs, options::OPT_MQ); |
| 1068 | Args.AddAllArgs(CmdArgs, options::OPT_MT); |
| 1069 | if (!Args.hasArg(options::OPT_M) && !Args.hasArg(options::OPT_MM) && |
| 1070 | (Args.hasArg(options::OPT_MD) || Args.hasArg(options::OPT_MMD))) { |
| 1071 | if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) { |
| 1072 | CmdArgs.push_back("-MQ"); |
| 1073 | CmdArgs.push_back(OutputOpt->getValue(Args)); |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | Args.AddLastArg(CmdArgs, options::OPT_remap); |
| 1078 | if (Args.hasArg(options::OPT_g3)) |
| 1079 | CmdArgs.push_back("-dD"); |
| 1080 | Args.AddLastArg(CmdArgs, options::OPT_H); |
| 1081 | |
| 1082 | AddCPPArgs(Args, CmdArgs); |
| 1083 | |
| 1084 | Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U, options::OPT_A); |
| 1085 | Args.AddAllArgs(CmdArgs, options::OPT_i_Group); |
| 1086 | |
| 1087 | for (InputInfoList::const_iterator |
| 1088 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1089 | const InputInfo &II = *it; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1090 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1091 | if (II.isPipe()) |
| 1092 | CmdArgs.push_back("-"); |
| 1093 | else |
| 1094 | CmdArgs.push_back(II.getFilename()); |
| 1095 | } |
| 1096 | |
| 1097 | Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA, |
| 1098 | options::OPT_Xpreprocessor); |
| 1099 | |
| 1100 | if (Args.hasArg(options::OPT_fmudflap)) { |
| 1101 | CmdArgs.push_back("-D_MUDFLAP"); |
| 1102 | CmdArgs.push_back("-include"); |
| 1103 | CmdArgs.push_back("mf-runtime.h"); |
| 1104 | } |
| 1105 | |
| 1106 | if (Args.hasArg(options::OPT_fmudflapth)) { |
| 1107 | CmdArgs.push_back("-D_MUDFLAP"); |
| 1108 | CmdArgs.push_back("-D_MUDFLAPTH"); |
| 1109 | CmdArgs.push_back("-include"); |
| 1110 | CmdArgs.push_back("mf-runtime.h"); |
| 1111 | } |
| 1112 | } |
| 1113 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1114 | void darwin::CC1::AddCPPArgs(const ArgList &Args, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1115 | ArgStringList &CmdArgs) const { |
| 1116 | // Derived from cpp spec. |
| 1117 | |
| 1118 | if (Args.hasArg(options::OPT_static)) { |
| 1119 | // The gcc spec is broken here, it refers to dynamic but |
| 1120 | // that has been translated. Start by being bug compatible. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1121 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1122 | // if (!Args.hasArg(arglist.parser.dynamicOption)) |
| 1123 | CmdArgs.push_back("-D__STATIC__"); |
| 1124 | } else |
| 1125 | CmdArgs.push_back("-D__DYNAMIC__"); |
| 1126 | |
| 1127 | if (Args.hasArg(options::OPT_pthread)) |
| 1128 | CmdArgs.push_back("-D_REENTRANT"); |
| 1129 | } |
| 1130 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1131 | void darwin::Preprocess::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1132 | Job &Dest, const InputInfo &Output, |
| 1133 | const InputInfoList &Inputs, |
| 1134 | const ArgList &Args, |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1135 | const char *LinkingOutput) const { |
| 1136 | ArgStringList CmdArgs; |
| 1137 | |
| 1138 | assert(Inputs.size() == 1 && "Unexpected number of inputs!"); |
| 1139 | |
| 1140 | CmdArgs.push_back("-E"); |
| 1141 | |
| 1142 | if (Args.hasArg(options::OPT_traditional) || |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1143 | Args.hasArg(options::OPT_traditional_cpp)) |
| 1144 | CmdArgs.push_back("-traditional-cpp"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1145 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1146 | ArgStringList OutputArgs; |
| 1147 | if (Output.isFilename()) { |
| 1148 | OutputArgs.push_back("-o"); |
| 1149 | OutputArgs.push_back(Output.getFilename()); |
| 1150 | } else { |
| 1151 | assert(Output.isPipe() && "Unexpected CC1 output."); |
| 1152 | } |
| 1153 | |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 1154 | if (Args.hasArg(options::OPT_E)) { |
| 1155 | AddCPPOptionsArgs(Args, CmdArgs, Inputs, OutputArgs); |
| 1156 | } else { |
| 1157 | AddCPPOptionsArgs(Args, CmdArgs, Inputs, ArgStringList()); |
| 1158 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 1159 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1160 | |
Daniel Dunbar | 8a2073a | 2009-04-03 01:27:06 +0000 | [diff] [blame] | 1161 | Args.AddAllArgs(CmdArgs, options::OPT_d_Group); |
| 1162 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1163 | const char *CC1Name = getCC1Name(Inputs[0].getType()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1164 | const char *Exec = |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1165 | Args.MakeArgString(getToolChain().GetProgramPath(C, CC1Name).c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 1166 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | void darwin::Compile::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1170 | Job &Dest, const InputInfo &Output, |
| 1171 | const InputInfoList &Inputs, |
| 1172 | const ArgList &Args, |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1173 | const char *LinkingOutput) const { |
| 1174 | const Driver &D = getToolChain().getHost().getDriver(); |
| 1175 | ArgStringList CmdArgs; |
| 1176 | |
| 1177 | assert(Inputs.size() == 1 && "Unexpected number of inputs!"); |
| 1178 | |
| 1179 | types::ID InputType = Inputs[0].getType(); |
| 1180 | const Arg *A; |
Eli Friedman | ceb5c5b | 2009-07-14 21:58:17 +0000 | [diff] [blame] | 1181 | if ((A = Args.getLastArg(options::OPT_traditional))) |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1182 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 1183 | << A->getAsString(Args) << "-E"; |
| 1184 | |
| 1185 | if (Output.getType() == types::TY_LLVMAsm) |
| 1186 | CmdArgs.push_back("-emit-llvm"); |
| 1187 | else if (Output.getType() == types::TY_LLVMBC) |
| 1188 | CmdArgs.push_back("-emit-llvm-bc"); |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 1189 | else if (Output.getType() == types::TY_AST) |
| 1190 | D.Diag(clang::diag::err_drv_no_ast_support) |
| 1191 | << getToolChain().getTripleString().c_str(); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1192 | |
| 1193 | ArgStringList OutputArgs; |
| 1194 | if (Output.getType() != types::TY_PCH) { |
| 1195 | OutputArgs.push_back("-o"); |
| 1196 | if (Output.isPipe()) |
| 1197 | OutputArgs.push_back("-"); |
| 1198 | else if (Output.isNothing()) |
| 1199 | OutputArgs.push_back("/dev/null"); |
| 1200 | else |
| 1201 | OutputArgs.push_back(Output.getFilename()); |
| 1202 | } |
| 1203 | |
| 1204 | // There is no need for this level of compatibility, but it makes |
| 1205 | // diffing easier. |
| 1206 | bool OutputArgsEarly = (Args.hasArg(options::OPT_fsyntax_only) || |
| 1207 | Args.hasArg(options::OPT_S)); |
| 1208 | |
| 1209 | if (types::getPreprocessedType(InputType) != types::TY_INVALID) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1210 | AddCPPUniqueOptionsArgs(Args, CmdArgs, Inputs); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1211 | if (OutputArgsEarly) { |
| 1212 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, OutputArgs); |
| 1213 | } else { |
| 1214 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, ArgStringList()); |
| 1215 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 1216 | } |
| 1217 | } else { |
| 1218 | CmdArgs.push_back("-fpreprocessed"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1219 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1220 | for (InputInfoList::const_iterator |
| 1221 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1222 | const InputInfo &II = *it; |
| 1223 | |
Daniel Dunbar | 5915fbf | 2009-09-01 16:57:46 +0000 | [diff] [blame] | 1224 | // Reject AST inputs. |
| 1225 | if (II.getType() == types::TY_AST) { |
| 1226 | D.Diag(clang::diag::err_drv_no_ast_support) |
| 1227 | << getToolChain().getTripleString().c_str(); |
| 1228 | return; |
| 1229 | } |
| 1230 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1231 | if (II.isPipe()) |
| 1232 | CmdArgs.push_back("-"); |
| 1233 | else |
| 1234 | CmdArgs.push_back(II.getFilename()); |
| 1235 | } |
| 1236 | |
| 1237 | if (OutputArgsEarly) { |
| 1238 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, OutputArgs); |
| 1239 | } else { |
| 1240 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, ArgStringList()); |
| 1241 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 1242 | } |
| 1243 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1244 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1245 | if (Output.getType() == types::TY_PCH) { |
| 1246 | assert(Output.isFilename() && "Invalid PCH output."); |
| 1247 | |
| 1248 | CmdArgs.push_back("-o"); |
| 1249 | // NOTE: gcc uses a temp .s file for this, but there doesn't seem |
| 1250 | // to be a good reason. |
| 1251 | CmdArgs.push_back("/dev/null"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1252 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1253 | CmdArgs.push_back("--output-pch="); |
| 1254 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1255 | } |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1256 | |
| 1257 | const char *CC1Name = getCC1Name(Inputs[0].getType()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1258 | const char *Exec = |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1259 | Args.MakeArgString(getToolChain().GetProgramPath(C, CC1Name).c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 1260 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1263 | void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1264 | Job &Dest, const InputInfo &Output, |
| 1265 | const InputInfoList &Inputs, |
| 1266 | const ArgList &Args, |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1267 | const char *LinkingOutput) const { |
| 1268 | ArgStringList CmdArgs; |
| 1269 | |
| 1270 | assert(Inputs.size() == 1 && "Unexpected number of inputs."); |
| 1271 | const InputInfo &Input = Inputs[0]; |
| 1272 | |
| 1273 | // Bit of a hack, this is only used for original inputs. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1274 | // |
Daniel Dunbar | 8e4fea6 | 2009-04-01 00:27:44 +0000 | [diff] [blame] | 1275 | // FIXME: This is broken for preprocessed .s inputs. |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1276 | if (Input.isFilename() && |
Daniel Dunbar | 8e4fea6 | 2009-04-01 00:27:44 +0000 | [diff] [blame] | 1277 | strcmp(Input.getFilename(), Input.getBaseInput()) == 0) { |
| 1278 | if (Args.hasArg(options::OPT_gstabs)) |
| 1279 | CmdArgs.push_back("--gstabs"); |
| 1280 | else if (Args.hasArg(options::OPT_g_Group)) |
| 1281 | CmdArgs.push_back("--gdwarf2"); |
| 1282 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1283 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1284 | // Derived from asm spec. |
Daniel Dunbar | cc6f803 | 2009-09-09 18:36:27 +0000 | [diff] [blame] | 1285 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1286 | |
Daniel Dunbar | cc6f803 | 2009-09-09 18:36:27 +0000 | [diff] [blame] | 1287 | if (!getDarwinToolChain().isIPhone() || |
| 1288 | Args.hasArg(options::OPT_force__cpusubtype__ALL)) |
| 1289 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
| 1290 | |
Daniel Dunbar | 0e2679d | 2009-08-24 22:26:16 +0000 | [diff] [blame] | 1291 | if (getToolChain().getTriple().getArch() != llvm::Triple::x86_64 && |
| 1292 | (Args.hasArg(options::OPT_mkernel) || |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1293 | Args.hasArg(options::OPT_static) || |
Daniel Dunbar | 0e2679d | 2009-08-24 22:26:16 +0000 | [diff] [blame] | 1294 | Args.hasArg(options::OPT_fapple_kext))) |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1295 | CmdArgs.push_back("-static"); |
| 1296 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1297 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 1298 | options::OPT_Xassembler); |
| 1299 | |
| 1300 | assert(Output.isFilename() && "Unexpected lipo output."); |
| 1301 | CmdArgs.push_back("-o"); |
| 1302 | CmdArgs.push_back(Output.getFilename()); |
| 1303 | |
| 1304 | if (Input.isPipe()) { |
| 1305 | CmdArgs.push_back("-"); |
| 1306 | } else { |
| 1307 | assert(Input.isFilename() && "Invalid input."); |
| 1308 | CmdArgs.push_back(Input.getFilename()); |
| 1309 | } |
| 1310 | |
| 1311 | // asm_final spec is empty. |
| 1312 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1313 | const char *Exec = |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1314 | Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 1315 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1316 | } |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1317 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1318 | /// Helper routine for seeing if we should use dsymutil; this is a |
| 1319 | /// gcc compatible hack, we should remove it and use the input |
| 1320 | /// type information. |
| 1321 | static bool isSourceSuffix(const char *Str) { |
| 1322 | // match: 'C', 'CPP', 'c', 'cc', 'cp', 'c++', 'cpp', 'cxx', 'm', |
| 1323 | // 'mm'. |
| 1324 | switch (strlen(Str)) { |
| 1325 | default: |
| 1326 | return false; |
| 1327 | case 1: |
| 1328 | return (memcmp(Str, "C", 1) == 0 || |
| 1329 | memcmp(Str, "c", 1) == 0 || |
| 1330 | memcmp(Str, "m", 1) == 0); |
| 1331 | case 2: |
| 1332 | return (memcmp(Str, "cc", 2) == 0 || |
| 1333 | memcmp(Str, "cp", 2) == 0 || |
| 1334 | memcmp(Str, "mm", 2) == 0); |
| 1335 | case 3: |
| 1336 | return (memcmp(Str, "CPP", 3) == 0 || |
| 1337 | memcmp(Str, "c++", 3) == 0 || |
| 1338 | memcmp(Str, "cpp", 3) == 0 || |
| 1339 | memcmp(Str, "cxx", 3) == 0); |
| 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) { |
| 1344 | for (unsigned i=0; i < 3; ++i) { |
| 1345 | if (A[i] > B[i]) return false; |
| 1346 | if (A[i] < B[i]) return true; |
| 1347 | } |
| 1348 | return false; |
| 1349 | } |
| 1350 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1351 | static bool isMacosxVersionLT(unsigned (&A)[3], |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1352 | unsigned V0, unsigned V1=0, unsigned V2=0) { |
| 1353 | unsigned B[3] = { V0, V1, V2 }; |
| 1354 | return isMacosxVersionLT(A, B); |
| 1355 | } |
| 1356 | |
Daniel Dunbar | 78dbd58 | 2009-09-04 18:35:31 +0000 | [diff] [blame] | 1357 | // FIXME: Can we tablegen this? |
| 1358 | static const char *GetArmArchForMArch(llvm::StringRef Value) { |
| 1359 | if (Value == "armv6k") |
| 1360 | return "armv6"; |
| 1361 | |
| 1362 | if (Value == "armv5tej") |
| 1363 | return "armv5"; |
| 1364 | |
| 1365 | if (Value == "xscale") |
| 1366 | return "xscale"; |
| 1367 | |
| 1368 | if (Value == "armv4t") |
| 1369 | return "armv4t"; |
| 1370 | |
| 1371 | if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" || |
| 1372 | Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" || |
| 1373 | Value == "armv7m") |
| 1374 | return "armv7"; |
| 1375 | |
| 1376 | return 0; |
| 1377 | } |
| 1378 | |
| 1379 | // FIXME: Can we tablegen this? |
| 1380 | static const char *GetArmArchForMCpu(llvm::StringRef Value) { |
| 1381 | if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" || |
| 1382 | Value == "arm946e-s" || Value == "arm966e-s" || |
| 1383 | Value == "arm968e-s" || Value == "arm10e" || |
| 1384 | Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" || |
| 1385 | Value == "arm1026ej-s") |
| 1386 | return "armv5"; |
| 1387 | |
| 1388 | if (Value == "xscale") |
| 1389 | return "xscale"; |
| 1390 | |
| 1391 | if (Value == "arm1136j-s" || Value == "arm1136jf-s" || |
| 1392 | Value == "arm1176jz-s" || Value == "arm1176jzf-s") |
| 1393 | return "armv6"; |
| 1394 | |
| 1395 | if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3") |
| 1396 | return "armv7"; |
| 1397 | |
| 1398 | return 0; |
| 1399 | } |
| 1400 | |
Daniel Dunbar | fbefe6b | 2009-09-09 18:36:20 +0000 | [diff] [blame] | 1401 | void darwin::DarwinTool::AddDarwinArch(const ArgList &Args, |
| 1402 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1403 | // Derived from darwin_arch spec. |
| 1404 | CmdArgs.push_back("-arch"); |
Daniel Dunbar | 78dbd58 | 2009-09-04 18:35:31 +0000 | [diff] [blame] | 1405 | |
| 1406 | switch (getToolChain().getTriple().getArch()) { |
| 1407 | default: |
| 1408 | CmdArgs.push_back(Args.MakeArgString(getToolChain().getArchName().c_str())); |
| 1409 | break; |
| 1410 | |
| 1411 | case llvm::Triple::arm: { |
Daniel Dunbar | 78dbd58 | 2009-09-04 18:35:31 +0000 | [diff] [blame] | 1412 | if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) { |
| 1413 | if (const char *Arch = GetArmArchForMArch(A->getValue(Args))) { |
| 1414 | CmdArgs.push_back(Arch); |
| 1415 | return; |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) { |
| 1420 | if (const char *Arch = GetArmArchForMCpu(A->getValue(Args))) { |
| 1421 | CmdArgs.push_back(Arch); |
| 1422 | return; |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | CmdArgs.push_back("arm"); |
| 1427 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
| 1428 | return; |
| 1429 | } |
| 1430 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
Daniel Dunbar | fbefe6b | 2009-09-09 18:36:20 +0000 | [diff] [blame] | 1433 | void darwin::DarwinTool::AddDarwinSubArch(const ArgList &Args, |
| 1434 | ArgStringList &CmdArgs) const { |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1435 | // Derived from darwin_subarch spec, not sure what the distinction |
| 1436 | // exists for but at least for this chain it is the same. |
| 1437 | AddDarwinArch(Args, CmdArgs); |
| 1438 | } |
| 1439 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1440 | void darwin::Link::AddLinkArgs(const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1441 | ArgStringList &CmdArgs) const { |
| 1442 | const Driver &D = getToolChain().getHost().getDriver(); |
| 1443 | |
| 1444 | // Derived from the "link" spec. |
| 1445 | Args.AddAllArgs(CmdArgs, options::OPT_static); |
| 1446 | if (!Args.hasArg(options::OPT_static)) |
| 1447 | CmdArgs.push_back("-dynamic"); |
| 1448 | if (Args.hasArg(options::OPT_fgnu_runtime)) { |
| 1449 | // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu |
| 1450 | // here. How do we wish to handle such things? |
| 1451 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1452 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1453 | if (!Args.hasArg(options::OPT_dynamiclib)) { |
| 1454 | if (Args.hasArg(options::OPT_force__cpusubtype__ALL)) { |
| 1455 | AddDarwinArch(Args, CmdArgs); |
| 1456 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
| 1457 | } else |
| 1458 | AddDarwinSubArch(Args, CmdArgs); |
| 1459 | |
| 1460 | Args.AddLastArg(CmdArgs, options::OPT_bundle); |
| 1461 | Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader); |
| 1462 | Args.AddAllArgs(CmdArgs, options::OPT_client__name); |
| 1463 | |
| 1464 | Arg *A; |
| 1465 | if ((A = Args.getLastArg(options::OPT_compatibility__version)) || |
| 1466 | (A = Args.getLastArg(options::OPT_current__version)) || |
| 1467 | (A = Args.getLastArg(options::OPT_install__name))) |
| 1468 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 1469 | << A->getAsString(Args) << "-dynamiclib"; |
| 1470 | |
| 1471 | Args.AddLastArg(CmdArgs, options::OPT_force__flat__namespace); |
| 1472 | Args.AddLastArg(CmdArgs, options::OPT_keep__private__externs); |
| 1473 | Args.AddLastArg(CmdArgs, options::OPT_private__bundle); |
| 1474 | } else { |
| 1475 | CmdArgs.push_back("-dylib"); |
| 1476 | |
| 1477 | Arg *A; |
| 1478 | if ((A = Args.getLastArg(options::OPT_bundle)) || |
| 1479 | (A = Args.getLastArg(options::OPT_bundle__loader)) || |
| 1480 | (A = Args.getLastArg(options::OPT_client__name)) || |
| 1481 | (A = Args.getLastArg(options::OPT_force__flat__namespace)) || |
| 1482 | (A = Args.getLastArg(options::OPT_keep__private__externs)) || |
| 1483 | (A = Args.getLastArg(options::OPT_private__bundle))) |
| 1484 | D.Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 1485 | << A->getAsString(Args) << "-dynamiclib"; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1486 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1487 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_compatibility__version, |
| 1488 | "-dylib_compatibility_version"); |
| 1489 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version, |
| 1490 | "-dylib_current_version"); |
| 1491 | |
| 1492 | if (Args.hasArg(options::OPT_force__cpusubtype__ALL)) { |
| 1493 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1494 | // NOTE: We don't add -force_cpusubtype_ALL on this path. Ok. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1495 | } else |
| 1496 | AddDarwinSubArch(Args, CmdArgs); |
| 1497 | |
| 1498 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name, |
| 1499 | "-dylib_install_name"); |
| 1500 | } |
| 1501 | |
| 1502 | Args.AddLastArg(CmdArgs, options::OPT_all__load); |
| 1503 | Args.AddAllArgs(CmdArgs, options::OPT_allowable__client); |
| 1504 | Args.AddLastArg(CmdArgs, options::OPT_bind__at__load); |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 1505 | if (getDarwinToolChain().isIPhone()) |
| 1506 | Args.AddLastArg(CmdArgs, options::OPT_arch__errors__fatal); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1507 | Args.AddLastArg(CmdArgs, options::OPT_dead__strip); |
| 1508 | Args.AddLastArg(CmdArgs, options::OPT_no__dead__strip__inits__and__terms); |
| 1509 | Args.AddAllArgs(CmdArgs, options::OPT_dylib__file); |
| 1510 | Args.AddLastArg(CmdArgs, options::OPT_dynamic); |
| 1511 | Args.AddAllArgs(CmdArgs, options::OPT_exported__symbols__list); |
| 1512 | Args.AddLastArg(CmdArgs, options::OPT_flat__namespace); |
| 1513 | Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names); |
| 1514 | Args.AddAllArgs(CmdArgs, options::OPT_image__base); |
| 1515 | Args.AddAllArgs(CmdArgs, options::OPT_init); |
| 1516 | |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 1517 | if (!Args.hasArg(options::OPT_mmacosx_version_min_EQ) && |
| 1518 | !Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { |
| 1519 | // Add default version min. |
| 1520 | if (!getDarwinToolChain().isIPhone()) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1521 | CmdArgs.push_back("-macosx_version_min"); |
| 1522 | CmdArgs.push_back(getDarwinToolChain().getMacosxVersionStr()); |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 1523 | } else { |
| 1524 | CmdArgs.push_back("-iphoneos_version_min"); |
| 1525 | CmdArgs.push_back(getDarwinToolChain().getIPhoneOSVersionStr()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1526 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1527 | } |
| 1528 | |
Daniel Dunbar | 30392de | 2009-09-04 18:35:21 +0000 | [diff] [blame] | 1529 | // Adding all arguments doesn't make sense here but this is what |
| 1530 | // gcc does. |
| 1531 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_mmacosx_version_min_EQ, |
| 1532 | "-macosx_version_min"); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1533 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_miphoneos_version_min_EQ, |
| 1534 | "-iphoneos_version_min"); |
| 1535 | Args.AddLastArg(CmdArgs, options::OPT_nomultidefs); |
| 1536 | Args.AddLastArg(CmdArgs, options::OPT_multi__module); |
| 1537 | Args.AddLastArg(CmdArgs, options::OPT_single__module); |
| 1538 | Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined); |
| 1539 | Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1540 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1541 | if (Args.hasArg(options::OPT_fpie)) |
| 1542 | CmdArgs.push_back("-pie"); |
| 1543 | |
| 1544 | Args.AddLastArg(CmdArgs, options::OPT_prebind); |
| 1545 | Args.AddLastArg(CmdArgs, options::OPT_noprebind); |
| 1546 | Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding); |
| 1547 | Args.AddLastArg(CmdArgs, options::OPT_prebind__all__twolevel__modules); |
| 1548 | Args.AddLastArg(CmdArgs, options::OPT_read__only__relocs); |
| 1549 | Args.AddAllArgs(CmdArgs, options::OPT_sectcreate); |
| 1550 | Args.AddAllArgs(CmdArgs, options::OPT_sectorder); |
| 1551 | Args.AddAllArgs(CmdArgs, options::OPT_seg1addr); |
| 1552 | Args.AddAllArgs(CmdArgs, options::OPT_segprot); |
| 1553 | Args.AddAllArgs(CmdArgs, options::OPT_segaddr); |
| 1554 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__only__addr); |
| 1555 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__write__addr); |
| 1556 | Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table); |
| 1557 | Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table__filename); |
| 1558 | Args.AddAllArgs(CmdArgs, options::OPT_sub__library); |
| 1559 | Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella); |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 1560 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1561 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_isysroot, "-syslibroot"); |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 1562 | if (getDarwinToolChain().isIPhone()) { |
| 1563 | if (!Args.hasArg(options::OPT_isysroot)) { |
| 1564 | CmdArgs.push_back("-syslibroot"); |
| 1565 | CmdArgs.push_back("/Developer/SDKs/Extra"); |
| 1566 | } |
| 1567 | } |
| 1568 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1569 | Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace); |
| 1570 | Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace__hints); |
| 1571 | Args.AddAllArgs(CmdArgs, options::OPT_umbrella); |
| 1572 | Args.AddAllArgs(CmdArgs, options::OPT_undefined); |
| 1573 | Args.AddAllArgs(CmdArgs, options::OPT_unexported__symbols__list); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1574 | |
Daniel Dunbar | d82f8fa | 2009-09-04 18:35:41 +0000 | [diff] [blame] | 1575 | Args.AddAllArgs(CmdArgs, options::OPT_weak__reference__mismatches); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1576 | if (!Args.hasArg(options::OPT_weak__reference__mismatches)) { |
| 1577 | CmdArgs.push_back("-weak_reference_mismatches"); |
| 1578 | CmdArgs.push_back("non-weak"); |
| 1579 | } |
| 1580 | |
| 1581 | Args.AddLastArg(CmdArgs, options::OPT_X_Flag); |
| 1582 | Args.AddAllArgs(CmdArgs, options::OPT_y); |
| 1583 | Args.AddLastArg(CmdArgs, options::OPT_w); |
| 1584 | Args.AddAllArgs(CmdArgs, options::OPT_pagezero__size); |
| 1585 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__); |
| 1586 | Args.AddLastArg(CmdArgs, options::OPT_seglinkedit); |
| 1587 | Args.AddLastArg(CmdArgs, options::OPT_noseglinkedit); |
| 1588 | Args.AddAllArgs(CmdArgs, options::OPT_sectalign); |
| 1589 | Args.AddAllArgs(CmdArgs, options::OPT_sectobjectsymbols); |
| 1590 | Args.AddAllArgs(CmdArgs, options::OPT_segcreate); |
| 1591 | Args.AddLastArg(CmdArgs, options::OPT_whyload); |
| 1592 | Args.AddLastArg(CmdArgs, options::OPT_whatsloaded); |
| 1593 | Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name); |
| 1594 | Args.AddLastArg(CmdArgs, options::OPT_dylinker); |
| 1595 | Args.AddLastArg(CmdArgs, options::OPT_Mach); |
| 1596 | } |
| 1597 | |
| 1598 | void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1599 | Job &Dest, const InputInfo &Output, |
| 1600 | const InputInfoList &Inputs, |
| 1601 | const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1602 | const char *LinkingOutput) const { |
| 1603 | assert(Output.getType() == types::TY_Image && "Invalid linker output type."); |
Daniel Dunbar | e0be8b1 | 2009-09-08 16:39:16 +0000 | [diff] [blame] | 1604 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1605 | // The logic here is derived from gcc's behavior; most of which |
| 1606 | // comes from specs (starting with link_command). Consult gcc for |
| 1607 | // more information. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1608 | ArgStringList CmdArgs; |
| 1609 | |
| 1610 | // I'm not sure why this particular decomposition exists in gcc, but |
| 1611 | // we follow suite for ease of comparison. |
| 1612 | AddLinkArgs(Args, CmdArgs); |
| 1613 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1614 | Args.AddAllArgs(CmdArgs, options::OPT_d_Flag); |
| 1615 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 1616 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 1617 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 1618 | Args.AddAllArgs(CmdArgs, options::OPT_u_Group); |
| 1619 | Args.AddAllArgs(CmdArgs, options::OPT_A); |
| 1620 | Args.AddLastArg(CmdArgs, options::OPT_e); |
| 1621 | Args.AddAllArgs(CmdArgs, options::OPT_m_Separate); |
| 1622 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
| 1623 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1624 | CmdArgs.push_back("-o"); |
| 1625 | CmdArgs.push_back(Output.getFilename()); |
| 1626 | |
| 1627 | unsigned MacosxVersion[3]; |
| 1628 | if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) { |
| 1629 | bool HadExtra; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1630 | if (!Driver::GetReleaseVersion(A->getValue(Args), MacosxVersion[0], |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1631 | MacosxVersion[1], MacosxVersion[2], |
| 1632 | HadExtra) || |
| 1633 | HadExtra) { |
| 1634 | const Driver &D = getToolChain().getHost().getDriver(); |
| 1635 | D.Diag(clang::diag::err_drv_invalid_version_number) |
| 1636 | << A->getAsString(Args); |
| 1637 | } |
| 1638 | } else { |
| 1639 | getDarwinToolChain().getMacosxVersion(MacosxVersion); |
| 1640 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1641 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1642 | if (!Args.hasArg(options::OPT_A) && |
| 1643 | !Args.hasArg(options::OPT_nostdlib) && |
| 1644 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 1645 | // Derived from startfile spec. |
| 1646 | if (Args.hasArg(options::OPT_dynamiclib)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1647 | // Derived from darwin_dylib1 spec. |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1648 | if (isMacosxVersionLT(MacosxVersion, 10, 5)) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1649 | CmdArgs.push_back("-ldylib1.o"); |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1650 | else if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1651 | CmdArgs.push_back("-ldylib1.10.5.o"); |
| 1652 | } else { |
| 1653 | if (Args.hasArg(options::OPT_bundle)) { |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1654 | if (!Args.hasArg(options::OPT_static)) { |
| 1655 | // Derived from darwin_bundle1 spec. |
| 1656 | if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
| 1657 | CmdArgs.push_back("-lbundle1.o"); |
| 1658 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1659 | } else { |
| 1660 | if (Args.hasArg(options::OPT_pg)) { |
| 1661 | if (Args.hasArg(options::OPT_static) || |
| 1662 | Args.hasArg(options::OPT_object) || |
| 1663 | Args.hasArg(options::OPT_preload)) { |
| 1664 | CmdArgs.push_back("-lgcrt0.o"); |
| 1665 | } else { |
| 1666 | CmdArgs.push_back("-lgcrt1.o"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1667 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1668 | // darwin_crt2 spec is empty. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1669 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1670 | } else { |
| 1671 | if (Args.hasArg(options::OPT_static) || |
| 1672 | Args.hasArg(options::OPT_object) || |
| 1673 | Args.hasArg(options::OPT_preload)) { |
| 1674 | CmdArgs.push_back("-lcrt0.o"); |
| 1675 | } else { |
| 1676 | // Derived from darwin_crt1 spec. |
Daniel Dunbar | ae33f8f | 2009-09-04 18:35:47 +0000 | [diff] [blame] | 1677 | if (getDarwinToolChain().isIPhone()) { |
| 1678 | CmdArgs.push_back("-lcrt1.o"); |
| 1679 | } else if (isMacosxVersionLT(MacosxVersion, 10, 5)) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1680 | CmdArgs.push_back("-lcrt1.o"); |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1681 | else if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1682 | CmdArgs.push_back("-lcrt1.10.5.o"); |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1683 | else |
| 1684 | CmdArgs.push_back("-lcrt1.10.6.o"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1685 | |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1686 | // darwin_crt2 spec is empty. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1687 | } |
| 1688 | } |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | if (Args.hasArg(options::OPT_shared_libgcc) && |
| 1693 | !Args.hasArg(options::OPT_miphoneos_version_min_EQ) && |
| 1694 | isMacosxVersionLT(MacosxVersion, 10, 5)) { |
| 1695 | const char *Str = getToolChain().GetFilePath(C, "crt3.o").c_str(); |
| 1696 | CmdArgs.push_back(Args.MakeArgString(Str)); |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1701 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1702 | if (Args.hasArg(options::OPT_fopenmp)) |
| 1703 | // This is more complicated in gcc... |
| 1704 | CmdArgs.push_back("-lgomp"); |
| 1705 | |
| 1706 | // FIXME: Derive these correctly. |
Daniel Dunbar | 302e2ea | 2009-09-09 22:32:41 +0000 | [diff] [blame^] | 1707 | llvm::StringRef TCDir = getDarwinToolChain().getToolChainDir(); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1708 | if (getToolChain().getArchName() == "x86_64") { |
Daniel Dunbar | 302e2ea | 2009-09-09 22:32:41 +0000 | [diff] [blame^] | 1709 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + TCDir + |
| 1710 | "/x86_64")); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1711 | // Intentionally duplicated for (temporary) gcc bug compatibility. |
Daniel Dunbar | 302e2ea | 2009-09-09 22:32:41 +0000 | [diff] [blame^] | 1712 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + TCDir + |
| 1713 | "/x86_64")); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1714 | } |
Daniel Dunbar | 302e2ea | 2009-09-09 22:32:41 +0000 | [diff] [blame^] | 1715 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + TCDir)); |
| 1716 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + TCDir)); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1717 | // Intentionally duplicated for (temporary) gcc bug compatibility. |
Daniel Dunbar | 302e2ea | 2009-09-09 22:32:41 +0000 | [diff] [blame^] | 1718 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + TCDir)); |
| 1719 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + TCDir + |
| 1720 | "/../../../" + TCDir)); |
| 1721 | CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + TCDir + |
| 1722 | "/../../..")); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1723 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1724 | for (InputInfoList::const_iterator |
| 1725 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1726 | const InputInfo &II = *it; |
| 1727 | if (II.isFilename()) |
| 1728 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1729 | else |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1730 | II.getInputArg().renderAsInput(Args, CmdArgs); |
| 1731 | } |
| 1732 | |
| 1733 | if (LinkingOutput) { |
| 1734 | CmdArgs.push_back("-arch_multiple"); |
| 1735 | CmdArgs.push_back("-final_output"); |
| 1736 | CmdArgs.push_back(LinkingOutput); |
| 1737 | } |
| 1738 | |
| 1739 | if (Args.hasArg(options::OPT_fprofile_arcs) || |
| 1740 | Args.hasArg(options::OPT_fprofile_generate) || |
| 1741 | Args.hasArg(options::OPT_fcreate_profile) || |
| 1742 | Args.hasArg(options::OPT_coverage)) |
| 1743 | CmdArgs.push_back("-lgcov"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1744 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1745 | if (Args.hasArg(options::OPT_fnested_functions)) |
| 1746 | CmdArgs.push_back("-allow_stack_execute"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1747 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1748 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 1749 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | edfa02b | 2009-04-08 06:06:21 +0000 | [diff] [blame] | 1750 | // FIXME: g++ is more complicated here, it tries to put -lstdc++ |
| 1751 | // before -lm, for example. |
| 1752 | if (getToolChain().getHost().getDriver().CCCIsCXX) |
| 1753 | CmdArgs.push_back("-lstdc++"); |
| 1754 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1755 | // link_ssp spec is empty. |
| 1756 | |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1757 | // Derived from libgcc and lib specs but refactored. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1758 | if (Args.hasArg(options::OPT_static)) { |
| 1759 | CmdArgs.push_back("-lgcc_static"); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1760 | } else { |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1761 | if (Args.hasArg(options::OPT_static_libgcc)) { |
| 1762 | CmdArgs.push_back("-lgcc_eh"); |
| 1763 | } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { |
| 1764 | // Derived from darwin_iphoneos_libgcc spec. |
Daniel Dunbar | ae33f8f | 2009-09-04 18:35:47 +0000 | [diff] [blame] | 1765 | if (getDarwinToolChain().isIPhone()) { |
| 1766 | CmdArgs.push_back("-lgcc_s.1"); |
| 1767 | } else { |
| 1768 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 1769 | } |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1770 | } else if (Args.hasArg(options::OPT_shared_libgcc) || |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 1771 | // FIXME: -fexceptions -fno-exceptions means no exceptions |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1772 | Args.hasArg(options::OPT_fexceptions) || |
| 1773 | Args.hasArg(options::OPT_fgnu_runtime)) { |
| 1774 | // FIXME: This is probably broken on 10.3? |
| 1775 | if (isMacosxVersionLT(MacosxVersion, 10, 5)) |
| 1776 | CmdArgs.push_back("-lgcc_s.10.4"); |
| 1777 | else if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
| 1778 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 1779 | } else { |
| 1780 | if (isMacosxVersionLT(MacosxVersion, 10, 3, 9)) |
| 1781 | ; // Do nothing. |
| 1782 | else if (isMacosxVersionLT(MacosxVersion, 10, 5)) |
| 1783 | CmdArgs.push_back("-lgcc_s.10.4"); |
| 1784 | else if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
| 1785 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 1786 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1787 | |
Daniel Dunbar | ae33f8f | 2009-09-04 18:35:47 +0000 | [diff] [blame] | 1788 | if (getDarwinToolChain().isIPhone() || |
| 1789 | isMacosxVersionLT(MacosxVersion, 10, 6)) { |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1790 | CmdArgs.push_back("-lgcc"); |
| 1791 | CmdArgs.push_back("-lSystem"); |
| 1792 | } else { |
| 1793 | CmdArgs.push_back("-lSystem"); |
| 1794 | CmdArgs.push_back("-lgcc"); |
| 1795 | } |
| 1796 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | if (!Args.hasArg(options::OPT_A) && |
| 1800 | !Args.hasArg(options::OPT_nostdlib) && |
| 1801 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 1802 | // endfile_spec is empty. |
| 1803 | } |
| 1804 | |
| 1805 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 1806 | Args.AddAllArgs(CmdArgs, options::OPT_F); |
| 1807 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1808 | const char *Exec = |
Daniel Dunbar | 9961293 | 2009-04-23 23:17:23 +0000 | [diff] [blame] | 1809 | Args.MakeArgString(getToolChain().GetProgramPath(C, "ld").c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 1810 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1811 | |
Daniel Dunbar | 0b46e1b | 2009-04-04 00:55:30 +0000 | [diff] [blame] | 1812 | // Find the first non-empty base input (we want to ignore linker |
| 1813 | // inputs). |
| 1814 | const char *BaseInput = ""; |
| 1815 | for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { |
| 1816 | if (Inputs[i].getBaseInput()[0] != '\0') { |
| 1817 | BaseInput = Inputs[i].getBaseInput(); |
| 1818 | break; |
| 1819 | } |
| 1820 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1821 | |
Daniel Dunbar | 3ed2945 | 2009-04-24 03:03:52 +0000 | [diff] [blame] | 1822 | // Run dsymutil if we are making an executable in a single step. |
| 1823 | // |
| 1824 | // FIXME: Currently we don't want to do this when we are part of a |
| 1825 | // universal build step, as this would end up creating stray temp |
| 1826 | // files. |
| 1827 | if (!LinkingOutput && |
| 1828 | Args.getLastArg(options::OPT_g_Group) && |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1829 | !Args.getLastArg(options::OPT_gstabs) && |
| 1830 | !Args.getLastArg(options::OPT_g0)) { |
| 1831 | // FIXME: This is gross, but matches gcc. The test only considers |
| 1832 | // the suffix (not the -x type), and then only of the first |
Daniel Dunbar | 0b46e1b | 2009-04-04 00:55:30 +0000 | [diff] [blame] | 1833 | // source input. Awesome. |
| 1834 | const char *Suffix = strrchr(BaseInput, '.'); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1835 | if (Suffix && isSourceSuffix(Suffix + 1)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1836 | const char *Exec = |
| 1837 | Args.MakeArgString(getToolChain().GetProgramPath(C, "dsymutil").c_str()); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1838 | ArgStringList CmdArgs; |
| 1839 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 1840 | C.getJobs().addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1841 | } |
| 1842 | } |
| 1843 | } |
| 1844 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1845 | void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1846 | Job &Dest, const InputInfo &Output, |
| 1847 | const InputInfoList &Inputs, |
| 1848 | const ArgList &Args, |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1849 | const char *LinkingOutput) const { |
| 1850 | ArgStringList CmdArgs; |
| 1851 | |
| 1852 | CmdArgs.push_back("-create"); |
| 1853 | assert(Output.isFilename() && "Unexpected lipo output."); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 1854 | |
| 1855 | CmdArgs.push_back("-output"); |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1856 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 1857 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1858 | for (InputInfoList::const_iterator |
| 1859 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1860 | const InputInfo &II = *it; |
| 1861 | assert(II.isFilename() && "Unexpected lipo input."); |
| 1862 | CmdArgs.push_back(II.getFilename()); |
| 1863 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1864 | const char *Exec = |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1865 | Args.MakeArgString(getToolChain().GetProgramPath(C, "lipo").c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 1866 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1867 | } |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1868 | |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1869 | void auroraux::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 1870 | Job &Dest, const InputInfo &Output, |
| 1871 | const InputInfoList &Inputs, |
| 1872 | const ArgList &Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1873 | const char *LinkingOutput) const { |
Edward O'Callaghan | e7925a0 | 2009-08-22 01:06:46 +0000 | [diff] [blame] | 1874 | ArgStringList CmdArgs; |
| 1875 | |
| 1876 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 1877 | options::OPT_Xassembler); |
| 1878 | |
| 1879 | CmdArgs.push_back("-o"); |
| 1880 | if (Output.isPipe()) |
| 1881 | CmdArgs.push_back("-"); |
| 1882 | else |
| 1883 | CmdArgs.push_back(Output.getFilename()); |
| 1884 | |
| 1885 | for (InputInfoList::const_iterator |
| 1886 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1887 | const InputInfo &II = *it; |
| 1888 | if (II.isPipe()) |
| 1889 | CmdArgs.push_back("-"); |
| 1890 | else |
| 1891 | CmdArgs.push_back(II.getFilename()); |
| 1892 | } |
| 1893 | |
| 1894 | const char *Exec = |
| 1895 | Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str()); |
| 1896 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
| 1897 | } |
| 1898 | |
| 1899 | void auroraux::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 1900 | Job &Dest, const InputInfo &Output, |
| 1901 | const InputInfoList &Inputs, |
| 1902 | const ArgList &Args, |
| 1903 | const char *LinkingOutput) const { |
| 1904 | const Driver &D = getToolChain().getHost().getDriver(); |
| 1905 | ArgStringList CmdArgs; |
| 1906 | |
| 1907 | if ((!Args.hasArg(options::OPT_nostdlib)) && |
| 1908 | (!Args.hasArg(options::OPT_shared))) { |
| 1909 | CmdArgs.push_back("-e"); |
| 1910 | CmdArgs.push_back("__start"); |
| 1911 | } |
| 1912 | |
| 1913 | if (Args.hasArg(options::OPT_static)) { |
| 1914 | CmdArgs.push_back("-Bstatic"); |
| 1915 | } else { |
| 1916 | CmdArgs.push_back("--eh-frame-hdr"); |
| 1917 | CmdArgs.push_back("-Bdynamic"); |
| 1918 | if (Args.hasArg(options::OPT_shared)) { |
| 1919 | CmdArgs.push_back("-shared"); |
| 1920 | } else { |
| 1921 | CmdArgs.push_back("-dynamic-linker"); |
| 1922 | CmdArgs.push_back("/lib/ld.so.1"); // 64Bit Path /lib/amd64/ld.so.1 |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | if (Output.isPipe()) { |
| 1927 | CmdArgs.push_back("-o"); |
| 1928 | CmdArgs.push_back("-"); |
| 1929 | } else if (Output.isFilename()) { |
| 1930 | CmdArgs.push_back("-o"); |
| 1931 | CmdArgs.push_back(Output.getFilename()); |
| 1932 | } else { |
| 1933 | assert(Output.isNothing() && "Invalid output."); |
| 1934 | } |
| 1935 | |
| 1936 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 1937 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 1938 | if (!Args.hasArg(options::OPT_shared)) { |
| 1939 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crt0.o").c_str())); |
| 1940 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbegin.o").c_str())); |
| 1941 | } else { |
| 1942 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbeginS.o").c_str())); |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | CmdArgs.push_back(MakeFormattedString(Args, |
| 1947 | llvm::format("-L/opt/gcc4/lib/gcc/%s/4.2.4", |
| 1948 | getToolChain().getTripleString().c_str()))); |
| 1949 | |
| 1950 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 1951 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 1952 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 1953 | |
| 1954 | for (InputInfoList::const_iterator |
| 1955 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1956 | const InputInfo &II = *it; |
| 1957 | |
| 1958 | // Don't try to pass LLVM inputs to a generic gcc. |
| 1959 | if (II.getType() == types::TY_LLVMBC) |
| 1960 | D.Diag(clang::diag::err_drv_no_linker_llvm_support) |
| 1961 | << getToolChain().getTripleString().c_str(); |
| 1962 | |
| 1963 | if (II.isPipe()) |
| 1964 | CmdArgs.push_back("-"); |
| 1965 | else if (II.isFilename()) |
| 1966 | CmdArgs.push_back(II.getFilename()); |
| 1967 | else |
| 1968 | II.getInputArg().renderAsInput(Args, CmdArgs); |
| 1969 | } |
| 1970 | |
| 1971 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 1972 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 1973 | // FIXME: For some reason GCC passes -lgcc before adding |
| 1974 | // the default system libraries. Just mimic this for now. |
| 1975 | CmdArgs.push_back("-lgcc"); |
| 1976 | |
| 1977 | if (Args.hasArg(options::OPT_pthread)) |
| 1978 | CmdArgs.push_back("-pthread"); |
| 1979 | if (!Args.hasArg(options::OPT_shared)) |
| 1980 | CmdArgs.push_back("-lc"); |
| 1981 | CmdArgs.push_back("-lgcc"); |
| 1982 | } |
| 1983 | |
| 1984 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 1985 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 1986 | if (!Args.hasArg(options::OPT_shared)) |
| 1987 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtend.o").c_str())); |
| 1988 | else |
| 1989 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtendS.o").c_str())); |
| 1990 | } |
| 1991 | |
| 1992 | const char *Exec = |
| 1993 | Args.MakeArgString(getToolChain().GetProgramPath(C, "ld").c_str()); |
| 1994 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
| 1995 | } |
| 1996 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 1997 | void openbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 1998 | Job &Dest, const InputInfo &Output, |
| 1999 | const InputInfoList &Inputs, |
| 2000 | const ArgList &Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2001 | const char *LinkingOutput) const { |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2002 | ArgStringList CmdArgs; |
| 2003 | |
| 2004 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 2005 | options::OPT_Xassembler); |
| 2006 | |
| 2007 | CmdArgs.push_back("-o"); |
| 2008 | if (Output.isPipe()) |
| 2009 | CmdArgs.push_back("-"); |
| 2010 | else |
| 2011 | CmdArgs.push_back(Output.getFilename()); |
| 2012 | |
| 2013 | for (InputInfoList::const_iterator |
| 2014 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 2015 | const InputInfo &II = *it; |
| 2016 | if (II.isPipe()) |
| 2017 | CmdArgs.push_back("-"); |
| 2018 | else |
| 2019 | CmdArgs.push_back(II.getFilename()); |
| 2020 | } |
| 2021 | |
| 2022 | const char *Exec = |
| 2023 | Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 2024 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | void openbsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 2028 | Job &Dest, const InputInfo &Output, |
| 2029 | const InputInfoList &Inputs, |
| 2030 | const ArgList &Args, |
| 2031 | const char *LinkingOutput) const { |
| 2032 | const Driver &D = getToolChain().getHost().getDriver(); |
| 2033 | ArgStringList CmdArgs; |
| 2034 | |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 2035 | if ((!Args.hasArg(options::OPT_nostdlib)) && |
| 2036 | (!Args.hasArg(options::OPT_shared))) { |
| 2037 | CmdArgs.push_back("-e"); |
| 2038 | CmdArgs.push_back("__start"); |
| 2039 | } |
| 2040 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2041 | if (Args.hasArg(options::OPT_static)) { |
| 2042 | CmdArgs.push_back("-Bstatic"); |
| 2043 | } else { |
| 2044 | CmdArgs.push_back("--eh-frame-hdr"); |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 2045 | CmdArgs.push_back("-Bdynamic"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2046 | if (Args.hasArg(options::OPT_shared)) { |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 2047 | CmdArgs.push_back("-shared"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2048 | } else { |
| 2049 | CmdArgs.push_back("-dynamic-linker"); |
| 2050 | CmdArgs.push_back("/usr/libexec/ld.so"); |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | if (Output.isPipe()) { |
| 2055 | CmdArgs.push_back("-o"); |
| 2056 | CmdArgs.push_back("-"); |
| 2057 | } else if (Output.isFilename()) { |
| 2058 | CmdArgs.push_back("-o"); |
| 2059 | CmdArgs.push_back(Output.getFilename()); |
| 2060 | } else { |
| 2061 | assert(Output.isNothing() && "Invalid output."); |
| 2062 | } |
| 2063 | |
| 2064 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 2065 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 2066 | if (!Args.hasArg(options::OPT_shared)) { |
| 2067 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crt0.o").c_str())); |
| 2068 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbegin.o").c_str())); |
| 2069 | } else { |
| 2070 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbeginS.o").c_str())); |
| 2071 | } |
| 2072 | } |
| 2073 | |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 2074 | CmdArgs.push_back(MakeFormattedString(Args, |
| 2075 | llvm::format("-L/usr/lib/gcc-lib/%s/3.3.5", |
| 2076 | getToolChain().getTripleString().c_str()))); |
| 2077 | |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2078 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 2079 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 2080 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 2081 | |
| 2082 | for (InputInfoList::const_iterator |
| 2083 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 2084 | const InputInfo &II = *it; |
| 2085 | |
| 2086 | // Don't try to pass LLVM inputs to a generic gcc. |
| 2087 | if (II.getType() == types::TY_LLVMBC) |
| 2088 | D.Diag(clang::diag::err_drv_no_linker_llvm_support) |
| 2089 | << getToolChain().getTripleString().c_str(); |
| 2090 | |
| 2091 | if (II.isPipe()) |
| 2092 | CmdArgs.push_back("-"); |
| 2093 | else if (II.isFilename()) |
| 2094 | CmdArgs.push_back(II.getFilename()); |
| 2095 | else |
| 2096 | II.getInputArg().renderAsInput(Args, CmdArgs); |
| 2097 | } |
| 2098 | |
| 2099 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 2100 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 2101 | // FIXME: For some reason GCC passes -lgcc before adding |
| 2102 | // the default system libraries. Just mimic this for now. |
| 2103 | CmdArgs.push_back("-lgcc"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2104 | |
| 2105 | if (Args.hasArg(options::OPT_pthread)) |
| 2106 | CmdArgs.push_back("-pthread"); |
Daniel Dunbar | 2bbcf66 | 2009-08-03 01:28:59 +0000 | [diff] [blame] | 2107 | if (!Args.hasArg(options::OPT_shared)) |
| 2108 | CmdArgs.push_back("-lc"); |
| 2109 | CmdArgs.push_back("-lgcc"); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 2113 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 2114 | if (!Args.hasArg(options::OPT_shared)) |
| 2115 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtend.o").c_str())); |
| 2116 | else |
| 2117 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtendS.o").c_str())); |
| 2118 | } |
| 2119 | |
| 2120 | const char *Exec = |
| 2121 | Args.MakeArgString(getToolChain().GetProgramPath(C, "ld").c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 2122 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | f7b8eec | 2009-06-29 20:52:51 +0000 | [diff] [blame] | 2123 | } |
Ed Schouten | c66a5a3 | 2009-04-02 19:13:12 +0000 | [diff] [blame] | 2124 | |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 2125 | void freebsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2126 | Job &Dest, const InputInfo &Output, |
| 2127 | const InputInfoList &Inputs, |
| 2128 | const ArgList &Args, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2129 | const char *LinkingOutput) const { |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 2130 | ArgStringList CmdArgs; |
| 2131 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 2132 | // When building 32-bit code on FreeBSD/amd64, we have to explicitly |
| 2133 | // instruct as in the base system to assemble 32-bit code. |
| 2134 | if (getToolChain().getArchName() == "i386") |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 2135 | CmdArgs.push_back("--32"); |
| 2136 | |
| 2137 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 2138 | options::OPT_Xassembler); |
| 2139 | |
| 2140 | CmdArgs.push_back("-o"); |
| 2141 | if (Output.isPipe()) |
| 2142 | CmdArgs.push_back("-"); |
| 2143 | else |
| 2144 | CmdArgs.push_back(Output.getFilename()); |
| 2145 | |
| 2146 | for (InputInfoList::const_iterator |
| 2147 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 2148 | const InputInfo &II = *it; |
| 2149 | if (II.isPipe()) |
| 2150 | CmdArgs.push_back("-"); |
| 2151 | else |
| 2152 | CmdArgs.push_back(II.getFilename()); |
| 2153 | } |
| 2154 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2155 | const char *Exec = |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 2156 | Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 2157 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 2158 | } |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 2159 | |
| 2160 | void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2161 | Job &Dest, const InputInfo &Output, |
| 2162 | const InputInfoList &Inputs, |
| 2163 | const ArgList &Args, |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 2164 | const char *LinkingOutput) const { |
| 2165 | const Driver &D = getToolChain().getHost().getDriver(); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 2166 | ArgStringList CmdArgs; |
| 2167 | |
| 2168 | if (Args.hasArg(options::OPT_static)) { |
| 2169 | CmdArgs.push_back("-Bstatic"); |
| 2170 | } else { |
| 2171 | CmdArgs.push_back("--eh-frame-hdr"); |
| 2172 | if (Args.hasArg(options::OPT_shared)) { |
| 2173 | CmdArgs.push_back("-Bshareable"); |
| 2174 | } else { |
| 2175 | CmdArgs.push_back("-dynamic-linker"); |
| 2176 | CmdArgs.push_back("/libexec/ld-elf.so.1"); |
| 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | // When building 32-bit code on FreeBSD/amd64, we have to explicitly |
| 2181 | // instruct ld in the base system to link 32-bit code. |
| 2182 | if (getToolChain().getArchName() == "i386") { |
| 2183 | CmdArgs.push_back("-m"); |
| 2184 | CmdArgs.push_back("elf_i386_fbsd"); |
| 2185 | } |
| 2186 | |
| 2187 | if (Output.isPipe()) { |
| 2188 | CmdArgs.push_back("-o"); |
| 2189 | CmdArgs.push_back("-"); |
| 2190 | } else if (Output.isFilename()) { |
| 2191 | CmdArgs.push_back("-o"); |
| 2192 | CmdArgs.push_back(Output.getFilename()); |
| 2193 | } else { |
| 2194 | assert(Output.isNothing() && "Invalid output."); |
| 2195 | } |
| 2196 | |
| 2197 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 2198 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 2199 | if (!Args.hasArg(options::OPT_shared)) { |
| 2200 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crt1.o").c_str())); |
| 2201 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crti.o").c_str())); |
| 2202 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbegin.o").c_str())); |
| 2203 | } else { |
| 2204 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crti.o").c_str())); |
| 2205 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbeginS.o").c_str())); |
| 2206 | } |
| 2207 | } |
| 2208 | |
| 2209 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 2210 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 2211 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 2212 | |
| 2213 | for (InputInfoList::const_iterator |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2214 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 2215 | const InputInfo &II = *it; |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 2216 | |
| 2217 | // Don't try to pass LLVM inputs to a generic gcc. |
| 2218 | if (II.getType() == types::TY_LLVMBC) |
| 2219 | D.Diag(clang::diag::err_drv_no_linker_llvm_support) |
| 2220 | << getToolChain().getTripleString().c_str(); |
| 2221 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 2222 | if (II.isPipe()) |
| 2223 | CmdArgs.push_back("-"); |
| 2224 | else if (II.isFilename()) |
| 2225 | CmdArgs.push_back(II.getFilename()); |
| 2226 | else |
| 2227 | II.getInputArg().renderAsInput(Args, CmdArgs); |
| 2228 | } |
| 2229 | |
| 2230 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 2231 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 2232 | // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding |
| 2233 | // the default system libraries. Just mimic this for now. |
| 2234 | CmdArgs.push_back("-lgcc"); |
| 2235 | if (Args.hasArg(options::OPT_static)) { |
| 2236 | CmdArgs.push_back("-lgcc_eh"); |
| 2237 | } else { |
| 2238 | CmdArgs.push_back("--as-needed"); |
| 2239 | CmdArgs.push_back("-lgcc_s"); |
| 2240 | CmdArgs.push_back("--no-as-needed"); |
| 2241 | } |
| 2242 | |
| 2243 | if (Args.hasArg(options::OPT_pthread)) |
| 2244 | CmdArgs.push_back("-lpthread"); |
| 2245 | CmdArgs.push_back("-lc"); |
| 2246 | |
| 2247 | CmdArgs.push_back("-lgcc"); |
| 2248 | if (Args.hasArg(options::OPT_static)) { |
| 2249 | CmdArgs.push_back("-lgcc_eh"); |
| 2250 | } else { |
| 2251 | CmdArgs.push_back("--as-needed"); |
| 2252 | CmdArgs.push_back("-lgcc_s"); |
| 2253 | CmdArgs.push_back("--no-as-needed"); |
| 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 2258 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 2259 | if (!Args.hasArg(options::OPT_shared)) |
| 2260 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtend.o").c_str())); |
| 2261 | else |
| 2262 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtendS.o").c_str())); |
| 2263 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtn.o").c_str())); |
| 2264 | } |
| 2265 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 2266 | const char *Exec = |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 2267 | Args.MakeArgString(getToolChain().GetProgramPath(C, "ld").c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 2268 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 2269 | } |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2270 | |
| 2271 | /// DragonFly Tools |
| 2272 | |
| 2273 | // For now, DragonFly Assemble does just about the same as for |
| 2274 | // FreeBSD, but this may change soon. |
| 2275 | void dragonfly::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
| 2276 | Job &Dest, const InputInfo &Output, |
| 2277 | const InputInfoList &Inputs, |
| 2278 | const ArgList &Args, |
| 2279 | const char *LinkingOutput) const { |
| 2280 | ArgStringList CmdArgs; |
| 2281 | |
| 2282 | // When building 32-bit code on DragonFly/pc64, we have to explicitly |
| 2283 | // instruct as in the base system to assemble 32-bit code. |
| 2284 | if (getToolChain().getArchName() == "i386") |
| 2285 | CmdArgs.push_back("--32"); |
| 2286 | |
| 2287 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 2288 | options::OPT_Xassembler); |
| 2289 | |
| 2290 | CmdArgs.push_back("-o"); |
| 2291 | if (Output.isPipe()) |
| 2292 | CmdArgs.push_back("-"); |
| 2293 | else |
| 2294 | CmdArgs.push_back(Output.getFilename()); |
| 2295 | |
| 2296 | for (InputInfoList::const_iterator |
| 2297 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 2298 | const InputInfo &II = *it; |
| 2299 | if (II.isPipe()) |
| 2300 | CmdArgs.push_back("-"); |
| 2301 | else |
| 2302 | CmdArgs.push_back(II.getFilename()); |
| 2303 | } |
| 2304 | |
| 2305 | const char *Exec = |
| 2306 | Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 2307 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | void dragonfly::Link::ConstructJob(Compilation &C, const JobAction &JA, |
| 2311 | Job &Dest, const InputInfo &Output, |
| 2312 | const InputInfoList &Inputs, |
| 2313 | const ArgList &Args, |
| 2314 | const char *LinkingOutput) const { |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 2315 | const Driver &D = getToolChain().getHost().getDriver(); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2316 | ArgStringList CmdArgs; |
| 2317 | |
| 2318 | if (Args.hasArg(options::OPT_static)) { |
| 2319 | CmdArgs.push_back("-Bstatic"); |
| 2320 | } else { |
| 2321 | if (Args.hasArg(options::OPT_shared)) |
| 2322 | CmdArgs.push_back("-Bshareable"); |
| 2323 | else { |
| 2324 | CmdArgs.push_back("-dynamic-linker"); |
| 2325 | CmdArgs.push_back("/usr/libexec/ld-elf.so.2"); |
| 2326 | } |
| 2327 | } |
| 2328 | |
| 2329 | // When building 32-bit code on DragonFly/pc64, we have to explicitly |
| 2330 | // instruct ld in the base system to link 32-bit code. |
| 2331 | if (getToolChain().getArchName() == "i386") { |
| 2332 | CmdArgs.push_back("-m"); |
| 2333 | CmdArgs.push_back("elf_i386"); |
| 2334 | } |
| 2335 | |
| 2336 | if (Output.isPipe()) { |
| 2337 | CmdArgs.push_back("-o"); |
| 2338 | CmdArgs.push_back("-"); |
| 2339 | } else if (Output.isFilename()) { |
| 2340 | CmdArgs.push_back("-o"); |
| 2341 | CmdArgs.push_back(Output.getFilename()); |
| 2342 | } else { |
| 2343 | assert(Output.isNothing() && "Invalid output."); |
| 2344 | } |
| 2345 | |
| 2346 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 2347 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 2348 | if (!Args.hasArg(options::OPT_shared)) { |
| 2349 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crt1.o").c_str())); |
| 2350 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crti.o").c_str())); |
| 2351 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbegin.o").c_str())); |
| 2352 | } else { |
| 2353 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crti.o").c_str())); |
| 2354 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbeginS.o").c_str())); |
| 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 2359 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 2360 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 2361 | |
| 2362 | for (InputInfoList::const_iterator |
| 2363 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 2364 | const InputInfo &II = *it; |
Daniel Dunbar | a8304f6 | 2009-05-02 20:14:53 +0000 | [diff] [blame] | 2365 | |
| 2366 | // Don't try to pass LLVM inputs to a generic gcc. |
| 2367 | if (II.getType() == types::TY_LLVMBC) |
| 2368 | D.Diag(clang::diag::err_drv_no_linker_llvm_support) |
| 2369 | << getToolChain().getTripleString().c_str(); |
| 2370 | |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2371 | if (II.isPipe()) |
| 2372 | CmdArgs.push_back("-"); |
| 2373 | else if (II.isFilename()) |
| 2374 | CmdArgs.push_back(II.getFilename()); |
| 2375 | else |
| 2376 | II.getInputArg().renderAsInput(Args, CmdArgs); |
| 2377 | } |
| 2378 | |
| 2379 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 2380 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 2381 | // FIXME: GCC passes on -lgcc, -lgcc_pic and a whole lot of |
| 2382 | // rpaths |
| 2383 | CmdArgs.push_back("-L/usr/lib/gcc41"); |
| 2384 | |
| 2385 | if (!Args.hasArg(options::OPT_static)) { |
| 2386 | CmdArgs.push_back("-rpath"); |
| 2387 | CmdArgs.push_back("/usr/lib/gcc41"); |
| 2388 | |
| 2389 | CmdArgs.push_back("-rpath-link"); |
| 2390 | CmdArgs.push_back("/usr/lib/gcc41"); |
| 2391 | |
| 2392 | CmdArgs.push_back("-rpath"); |
| 2393 | CmdArgs.push_back("/usr/lib"); |
| 2394 | |
| 2395 | CmdArgs.push_back("-rpath-link"); |
| 2396 | CmdArgs.push_back("/usr/lib"); |
| 2397 | } |
| 2398 | |
| 2399 | if (Args.hasArg(options::OPT_shared)) { |
| 2400 | CmdArgs.push_back("-lgcc_pic"); |
| 2401 | } else { |
| 2402 | CmdArgs.push_back("-lgcc"); |
| 2403 | } |
| 2404 | |
| 2405 | |
| 2406 | if (Args.hasArg(options::OPT_pthread)) |
| 2407 | CmdArgs.push_back("-lthread_xu"); |
| 2408 | |
| 2409 | if (!Args.hasArg(options::OPT_nolibc)) { |
| 2410 | CmdArgs.push_back("-lc"); |
| 2411 | } |
| 2412 | |
| 2413 | if (Args.hasArg(options::OPT_shared)) { |
| 2414 | CmdArgs.push_back("-lgcc_pic"); |
| 2415 | } else { |
| 2416 | CmdArgs.push_back("-lgcc"); |
| 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 2421 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 2422 | if (!Args.hasArg(options::OPT_shared)) |
| 2423 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtend.o").c_str())); |
| 2424 | else |
| 2425 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtendS.o").c_str())); |
| 2426 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtn.o").c_str())); |
| 2427 | } |
| 2428 | |
| 2429 | const char *Exec = |
| 2430 | Args.MakeArgString(getToolChain().GetProgramPath(C, "ld").c_str()); |
Daniel Dunbar | cae087e | 2009-07-01 19:02:28 +0000 | [diff] [blame] | 2431 | Dest.addCommand(new Command(JA, Exec, CmdArgs)); |
Daniel Dunbar | 11e1b40 | 2009-05-02 18:28:39 +0000 | [diff] [blame] | 2432 | } |