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