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