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