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