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