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