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