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