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