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