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