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