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