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