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