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