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