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 | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 15 | #include "clang/Driver/Driver.h" // FIXME: Remove? |
| 16 | #include "clang/Driver/DriverDiagnostic.h" // FIXME: Remove? |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 17 | #include "clang/Driver/Compilation.h" |
| 18 | #include "clang/Driver/Job.h" |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 19 | #include "clang/Driver/HostInfo.h" |
| 20 | #include "clang/Driver/Option.h" |
| 21 | #include "clang/Driver/ToolChain.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 22 | #include "clang/Driver/Util.h" |
| 23 | |
| 24 | #include "llvm/ADT/SmallVector.h" |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Format.h" |
| 26 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 27 | |
| 28 | #include "InputInfo.h" |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 29 | #include "ToolChains.h" |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 30 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 31 | using namespace clang::driver; |
| 32 | using namespace clang::driver::tools; |
| 33 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 34 | void Clang::AddPreprocessingOptions(const Driver &D, |
| 35 | const ArgList &Args, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 36 | ArgStringList &CmdArgs, |
| 37 | const InputInfo &Output, |
| 38 | const InputInfoList &Inputs) const { |
| 39 | // Handle dependency file generation. |
| 40 | Arg *A; |
| 41 | if ((A = Args.getLastArg(options::OPT_M)) || |
| 42 | (A = Args.getLastArg(options::OPT_MM)) || |
| 43 | (A = Args.getLastArg(options::OPT_MD)) || |
| 44 | (A = Args.getLastArg(options::OPT_MMD))) { |
| 45 | // Determine the output location. |
| 46 | const char *DepFile; |
| 47 | if (Output.getType() == types::TY_Dependencies) { |
| 48 | if (Output.isPipe()) |
| 49 | DepFile = "-"; |
| 50 | else |
| 51 | DepFile = Output.getFilename(); |
| 52 | } else if (Arg *MF = Args.getLastArg(options::OPT_MF)) { |
| 53 | DepFile = MF->getValue(Args); |
| 54 | } else if (A->getOption().getId() == options::OPT_M || |
| 55 | A->getOption().getId() == options::OPT_MM) { |
| 56 | DepFile = "-"; |
| 57 | } else { |
| 58 | DepFile = darwin::CC1::getDependencyFileName(Args, Inputs); |
| 59 | } |
| 60 | CmdArgs.push_back("-dependency-file"); |
| 61 | CmdArgs.push_back(DepFile); |
| 62 | |
| 63 | // Add an -MT option if the user didn't specify their own. |
| 64 | // FIXME: This should use -MQ, when we support it. |
| 65 | if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) { |
| 66 | const char *DepTarget; |
| 67 | |
| 68 | // If user provided -o, that is the dependency target, except |
| 69 | // when we are only generating a dependency file. |
| 70 | Arg *OutputOpt = Args.getLastArg(options::OPT_o); |
| 71 | if (OutputOpt && Output.getType() != types::TY_Dependencies) { |
| 72 | DepTarget = OutputOpt->getValue(Args); |
| 73 | } else { |
| 74 | // Otherwise derive from the base input. |
| 75 | // |
| 76 | // FIXME: This should use the computed output file location. |
| 77 | llvm::sys::Path P(Inputs[0].getBaseInput()); |
| 78 | |
| 79 | P.eraseSuffix(); |
| 80 | P.appendSuffix("o"); |
| 81 | DepTarget = Args.MakeArgString(P.getLast().c_str()); |
| 82 | } |
| 83 | |
| 84 | CmdArgs.push_back("-MT"); |
| 85 | CmdArgs.push_back(DepTarget); |
| 86 | } |
| 87 | |
| 88 | if (A->getOption().getId() == options::OPT_M || |
| 89 | A->getOption().getId() == options::OPT_MD) |
| 90 | CmdArgs.push_back("-sys-header-deps"); |
| 91 | } |
| 92 | |
| 93 | Args.AddLastArg(CmdArgs, options::OPT_MP); |
| 94 | Args.AddAllArgs(CmdArgs, options::OPT_MT); |
| 95 | |
| 96 | // FIXME: Use iterator. |
| 97 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 98 | // Add -i* options, and automatically translate to |
| 99 | // -include-pch/-include-pth for transparent PCH support. It's |
| 100 | // wonky, but we include looking for .gch so we can support seamless |
| 101 | // replacement into a build system already set up to be generating |
| 102 | // .gch files. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 103 | for (ArgList::const_iterator |
| 104 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 105 | const Arg *A = *it; |
| 106 | if (!A->getOption().matches(options::OPT_clang_i_Group)) |
| 107 | continue; |
| 108 | |
| 109 | if (A->getOption().matches(options::OPT_include)) { |
| 110 | bool FoundPTH = false; |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 111 | bool FoundPCH = false; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 112 | llvm::sys::Path P(A->getValue(Args)); |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 113 | if (D.CCCUsePCH) { |
| 114 | P.appendSuffix("pch"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 115 | if (P.exists()) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 116 | FoundPCH = true; |
| 117 | else |
| 118 | P.eraseSuffix(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 121 | if (!FoundPCH) { |
| 122 | P.appendSuffix("pth"); |
| 123 | if (P.exists()) |
| 124 | FoundPTH = true; |
| 125 | else |
| 126 | P.eraseSuffix(); |
| 127 | } |
| 128 | |
| 129 | if (!FoundPCH && !FoundPTH) { |
| 130 | P.appendSuffix("gch"); |
| 131 | if (P.exists()) { |
| 132 | FoundPCH = D.CCCUsePCH; |
| 133 | FoundPTH = !D.CCCUsePCH; |
| 134 | } |
| 135 | else |
| 136 | P.eraseSuffix(); |
| 137 | } |
| 138 | |
| 139 | if (FoundPCH || FoundPTH) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 140 | A->claim(); |
Daniel Dunbar | ea71a5b | 2009-04-28 19:38:45 +0000 | [diff] [blame] | 141 | if (D.CCCUsePCH) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 142 | CmdArgs.push_back("-include-pch"); |
| 143 | else |
| 144 | CmdArgs.push_back("-include-pth"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 145 | CmdArgs.push_back(Args.MakeArgString(P.c_str())); |
| 146 | continue; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // Not translated, render as usual. |
| 151 | A->claim(); |
| 152 | A->render(Args, CmdArgs); |
| 153 | } |
| 154 | |
| 155 | Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U); |
| 156 | Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F); |
| 157 | |
| 158 | // Add -Wp, and -Xassembler if using the preprocessor. |
| 159 | |
| 160 | // FIXME: There is a very unfortunate problem here, some troubled |
| 161 | // souls abuse -Wp, to pass preprocessor options in gcc syntax. To |
| 162 | // really support that we would have to parse and then translate |
| 163 | // those options. :( |
| 164 | Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA, |
| 165 | options::OPT_Xpreprocessor); |
| 166 | } |
| 167 | |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 168 | void Clang::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | 871adcf | 2009-03-18 07:06:02 +0000 | [diff] [blame] | 169 | Job &Dest, |
| 170 | const InputInfo &Output, |
Daniel Dunbar | 62cf601 | 2009-03-18 06:07:59 +0000 | [diff] [blame] | 171 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 172 | const ArgList &Args, |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 173 | const char *LinkingOutput) const { |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 174 | const Driver &D = getToolChain().getHost().getDriver(); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 175 | ArgStringList CmdArgs; |
| 176 | |
Daniel Dunbar | 077ba6a | 2009-03-31 20:53:55 +0000 | [diff] [blame] | 177 | assert(Inputs.size() == 1 && "Unable to handle multiple inputs."); |
| 178 | |
Daniel Dunbar | af07f93 | 2009-03-31 17:35:15 +0000 | [diff] [blame] | 179 | CmdArgs.push_back("-triple"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 180 | const char *TripleStr = |
Daniel Dunbar | af07f93 | 2009-03-31 17:35:15 +0000 | [diff] [blame] | 181 | Args.MakeArgString(getToolChain().getTripleString().c_str()); |
| 182 | CmdArgs.push_back(TripleStr); |
| 183 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 184 | if (isa<AnalyzeJobAction>(JA)) { |
| 185 | assert(JA.getType() == types::TY_Plist && "Invalid output type."); |
| 186 | CmdArgs.push_back("-analyze"); |
| 187 | } else if (isa<PreprocessJobAction>(JA)) { |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 188 | if (Output.getType() == types::TY_Dependencies) |
| 189 | CmdArgs.push_back("-Eonly"); |
| 190 | else |
| 191 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 192 | } else if (isa<PrecompileJobAction>(JA)) { |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 193 | if (D.CCCUsePCH) |
| 194 | CmdArgs.push_back("-emit-pch"); |
| 195 | else |
| 196 | CmdArgs.push_back("-emit-pth"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 197 | } else { |
| 198 | assert(isa<CompileJobAction>(JA) && "Invalid action for clang tool."); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 199 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 200 | if (JA.getType() == types::TY_Nothing) { |
| 201 | CmdArgs.push_back("-fsyntax-only"); |
| 202 | } else if (JA.getType() == types::TY_LLVMAsm) { |
| 203 | CmdArgs.push_back("-emit-llvm"); |
| 204 | } else if (JA.getType() == types::TY_LLVMBC) { |
| 205 | CmdArgs.push_back("-emit-llvm-bc"); |
| 206 | } else if (JA.getType() == types::TY_PP_Asm) { |
| 207 | CmdArgs.push_back("-S"); |
| 208 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 211 | // The make clang go fast button. |
| 212 | CmdArgs.push_back("-disable-free"); |
| 213 | |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 214 | // Set the main file name, so that debug info works even with |
| 215 | // -save-temps. |
| 216 | CmdArgs.push_back("-main-file-name"); |
| 217 | CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs)); |
| 218 | |
Daniel Dunbar | 3bbc753 | 2009-04-08 18:03:55 +0000 | [diff] [blame] | 219 | // Some flags which affect the language (via preprocessor |
| 220 | // defines). See darwin::CC1::AddCPPArgs. |
| 221 | if (Args.hasArg(options::OPT_static)) |
| 222 | CmdArgs.push_back("-static-define"); |
| 223 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 224 | if (isa<AnalyzeJobAction>(JA)) { |
| 225 | // Add default argument set. |
| 226 | // |
| 227 | // FIXME: Move into clang? |
| 228 | CmdArgs.push_back("-warn-dead-stores"); |
| 229 | CmdArgs.push_back("-checker-cfref"); |
Ted Kremenek | 9b646da | 2009-03-25 00:38:14 +0000 | [diff] [blame] | 230 | CmdArgs.push_back("-analyzer-eagerly-assume"); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 231 | CmdArgs.push_back("-warn-objc-methodsigs"); |
| 232 | // Do not enable the missing -dealloc check. |
| 233 | // '-warn-objc-missing-dealloc', |
| 234 | CmdArgs.push_back("-warn-objc-unused-ivars"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 235 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 236 | CmdArgs.push_back("-analyzer-output=plist"); |
| 237 | |
| 238 | // Add -Xanalyzer arguments when running as analyzer. |
| 239 | Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer); |
| 240 | } else { |
| 241 | // Perform argument translation for LLVM backend. This |
| 242 | // takes some care in reconciling with llvm-gcc. The |
| 243 | // issue is that llvm-gcc translates these options based on |
| 244 | // the values in cc1, whereas we are processing based on |
| 245 | // the driver arguments. |
| 246 | // |
| 247 | // FIXME: This is currently broken for -f flags when -fno |
| 248 | // variants are present. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 249 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 250 | // This comes from the default translation the driver + cc1 |
| 251 | // would do to enable flag_pic. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 252 | // |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 253 | // FIXME: Centralize this code. |
| 254 | bool PICEnabled = (Args.hasArg(options::OPT_fPIC) || |
| 255 | Args.hasArg(options::OPT_fpic) || |
| 256 | Args.hasArg(options::OPT_fPIE) || |
| 257 | Args.hasArg(options::OPT_fpie)); |
| 258 | bool PICDisabled = (Args.hasArg(options::OPT_mkernel) || |
| 259 | Args.hasArg(options::OPT_static)); |
| 260 | const char *Model = getToolChain().GetForcedPicModel(); |
| 261 | if (!Model) { |
| 262 | if (Args.hasArg(options::OPT_mdynamic_no_pic)) |
| 263 | Model = "dynamic-no-pic"; |
| 264 | else if (PICDisabled) |
| 265 | Model = "static"; |
| 266 | else if (PICEnabled) |
| 267 | Model = "pic"; |
| 268 | else |
| 269 | Model = getToolChain().GetDefaultRelocationModel(); |
| 270 | } |
| 271 | CmdArgs.push_back("--relocation-model"); |
| 272 | CmdArgs.push_back(Model); |
| 273 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 274 | // Infer the __PIC__ value. |
Daniel Dunbar | 9fd0b1f | 2009-04-08 03:03:23 +0000 | [diff] [blame] | 275 | // |
| 276 | // FIXME: This isn't quite right on Darwin, which always sets |
| 277 | // __PIC__=2. |
| 278 | if (strcmp(Model, "pic") == 0 || strcmp(Model, "dynamic-no-pic") == 0) { |
| 279 | if (Args.hasArg(options::OPT_fPIC)) |
| 280 | CmdArgs.push_back("-pic-level=2"); |
| 281 | else |
| 282 | CmdArgs.push_back("-pic-level=1"); |
| 283 | } |
| 284 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 285 | if (Args.hasArg(options::OPT_ftime_report)) |
| 286 | CmdArgs.push_back("--time-passes"); |
| 287 | // FIXME: Set --enable-unsafe-fp-math. |
| 288 | if (!Args.hasArg(options::OPT_fomit_frame_pointer)) |
| 289 | CmdArgs.push_back("--disable-fp-elim"); |
| 290 | if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss, |
| 291 | options::OPT_fno_zero_initialized_in_bss, |
| 292 | true)) |
| 293 | CmdArgs.push_back("--nozero-initialized-in-bss"); |
Daniel Dunbar | b3fd500 | 2009-03-24 17:59:06 +0000 | [diff] [blame] | 294 | if (Args.hasArg(options::OPT_dA) || Args.hasArg(options::OPT_fverbose_asm)) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 295 | CmdArgs.push_back("--asm-verbose"); |
| 296 | if (Args.hasArg(options::OPT_fdebug_pass_structure)) |
| 297 | CmdArgs.push_back("--debug-pass=Structure"); |
| 298 | if (Args.hasArg(options::OPT_fdebug_pass_arguments)) |
| 299 | CmdArgs.push_back("--debug-pass=Arguments"); |
| 300 | // FIXME: set --inline-threshhold=50 if (optimize_size || optimize |
| 301 | // < 3) |
| 302 | if (Args.hasFlag(options::OPT_funwind_tables, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 303 | options::OPT_fno_unwind_tables, |
Daniel Dunbar | 9c7db4a | 2009-04-25 05:49:54 +0000 | [diff] [blame] | 304 | (getToolChain().IsUnwindTablesDefault() && |
| 305 | !Args.hasArg(options::OPT_mkernel)))) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 306 | CmdArgs.push_back("--unwind-tables=1"); |
| 307 | else |
| 308 | CmdArgs.push_back("--unwind-tables=0"); |
| 309 | if (!Args.hasFlag(options::OPT_mred_zone, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 310 | options::OPT_mno_red_zone, |
Daniel Dunbar | 8abf881 | 2009-04-25 05:33:23 +0000 | [diff] [blame] | 311 | true) || |
| 312 | Args.hasArg(options::OPT_mkernel) || |
| 313 | Args.hasArg(options::OPT_fapple_kext)) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 314 | CmdArgs.push_back("--disable-red-zone"); |
| 315 | if (Args.hasFlag(options::OPT_msoft_float, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 316 | options::OPT_mno_soft_float, |
| 317 | false)) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 318 | CmdArgs.push_back("--soft-float"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 319 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 320 | // FIXME: Need target hooks. |
| 321 | if (memcmp(getToolChain().getPlatform().c_str(), "darwin", 6) == 0) { |
| 322 | if (getToolChain().getArchName() == "x86_64") |
| 323 | CmdArgs.push_back("--mcpu=core2"); |
| 324 | else if (getToolChain().getArchName() == "i386") |
| 325 | CmdArgs.push_back("--mcpu=yonah"); |
| 326 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 327 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 328 | // FIXME: Ignores ordering. Also, we need to find a realistic |
| 329 | // solution for this. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 330 | static const struct { |
| 331 | options::ID Pos, Neg; |
| 332 | const char *Name; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 333 | } FeatureOptions[] = { |
| 334 | { options::OPT_mmmx, options::OPT_mno_mmx, "mmx" }, |
| 335 | { options::OPT_msse, options::OPT_mno_sse, "sse" }, |
| 336 | { options::OPT_msse2, options::OPT_mno_sse2, "sse2" }, |
| 337 | { options::OPT_msse3, options::OPT_mno_sse3, "sse3" }, |
| 338 | { options::OPT_mssse3, options::OPT_mno_ssse3, "ssse3" }, |
| 339 | { options::OPT_msse41, options::OPT_mno_sse41, "sse41" }, |
| 340 | { options::OPT_msse42, options::OPT_mno_sse42, "sse42" }, |
| 341 | { options::OPT_msse4a, options::OPT_mno_sse4a, "sse4a" }, |
| 342 | { options::OPT_m3dnow, options::OPT_mno_3dnow, "3dnow" }, |
| 343 | { options::OPT_m3dnowa, options::OPT_mno_3dnowa, "3dnowa" } |
| 344 | }; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 345 | const unsigned NumFeatureOptions = |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 346 | sizeof(FeatureOptions)/sizeof(FeatureOptions[0]); |
| 347 | |
| 348 | // FIXME: Avoid std::string |
| 349 | std::string Attrs; |
| 350 | for (unsigned i=0; i < NumFeatureOptions; ++i) { |
| 351 | if (Args.hasArg(FeatureOptions[i].Pos)) { |
Daniel Dunbar | 55b3b5f | 2009-03-19 17:36:04 +0000 | [diff] [blame] | 352 | if (!Attrs.empty()) |
| 353 | Attrs += ','; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 354 | Attrs += '+'; |
| 355 | Attrs += FeatureOptions[i].Name; |
| 356 | } else if (Args.hasArg(FeatureOptions[i].Neg)) { |
Daniel Dunbar | 55b3b5f | 2009-03-19 17:36:04 +0000 | [diff] [blame] | 357 | if (!Attrs.empty()) |
| 358 | Attrs += ','; |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 359 | Attrs += '-'; |
| 360 | Attrs += FeatureOptions[i].Name; |
| 361 | } |
| 362 | } |
| 363 | if (!Attrs.empty()) { |
| 364 | CmdArgs.push_back("--mattr"); |
| 365 | CmdArgs.push_back(Args.MakeArgString(Attrs.c_str())); |
| 366 | } |
| 367 | |
| 368 | if (Args.hasFlag(options::OPT_fmath_errno, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 369 | options::OPT_fno_math_errno, |
| 370 | getToolChain().IsMathErrnoDefault())) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 371 | CmdArgs.push_back("--fmath-errno=1"); |
| 372 | else |
| 373 | CmdArgs.push_back("--fmath-errno=0"); |
| 374 | |
| 375 | if (Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) { |
| 376 | CmdArgs.push_back("--limit-float-precision"); |
| 377 | CmdArgs.push_back(A->getValue(Args)); |
| 378 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 379 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 380 | // FIXME: Add --stack-protector-buffer-size=<xxx> on |
| 381 | // -fstack-protect. |
| 382 | |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 383 | Arg *Unsupported; |
| 384 | if ((Unsupported = Args.getLastArg(options::OPT_MG)) || |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 385 | (Unsupported = Args.getLastArg(options::OPT_MQ))) |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 386 | D.Diag(clang::diag::err_drv_unsupported_opt) |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 387 | << Unsupported->getOption().getName(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | Args.AddAllArgs(CmdArgs, options::OPT_v); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 391 | Args.AddLastArg(CmdArgs, options::OPT_P); |
Daniel Dunbar | 2ac9fc2 | 2009-04-07 21:42:00 +0000 | [diff] [blame] | 392 | Args.AddLastArg(CmdArgs, options::OPT_mmacosx_version_min_EQ); |
Daniel Dunbar | ff8857a | 2009-04-10 20:11:50 +0000 | [diff] [blame] | 393 | Args.AddLastArg(CmdArgs, options::OPT_miphoneos_version_min_EQ); |
Fariborz Jahanian | 448f5e6 | 2009-04-17 03:04:15 +0000 | [diff] [blame] | 394 | Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 395 | |
| 396 | // Special case debug options to only pass -g to clang. This is |
| 397 | // wrong. |
| 398 | if (Args.hasArg(options::OPT_g_Group)) |
| 399 | CmdArgs.push_back("-g"); |
| 400 | |
| 401 | Args.AddLastArg(CmdArgs, options::OPT_nostdinc); |
| 402 | |
Daniel Dunbar | 2ac9fc2 | 2009-04-07 21:42:00 +0000 | [diff] [blame] | 403 | Args.AddLastArg(CmdArgs, options::OPT_isysroot); |
| 404 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 405 | // Add preprocessing options like -I, -D, etc. if we are using the |
| 406 | // preprocessor. |
| 407 | // |
| 408 | // FIXME: Support -fpreprocessed |
| 409 | types::ID InputType = Inputs[0].getType(); |
| 410 | if (types::getPreprocessedType(InputType) != types::TY_INVALID) |
Douglas Gregor | df91ef3 | 2009-04-18 00:34:01 +0000 | [diff] [blame] | 411 | AddPreprocessingOptions(D, Args, CmdArgs, Output, Inputs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 412 | |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 413 | // Manually translate -O to -O1 and -O4 to -O3; let clang reject |
| 414 | // others. |
| 415 | if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 416 | if (A->getOption().getId() == options::OPT_O4) |
Daniel Dunbar | 337a627 | 2009-03-24 20:17:30 +0000 | [diff] [blame] | 417 | CmdArgs.push_back("-O3"); |
| 418 | else if (A->getValue(Args)[0] == '\0') |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 419 | CmdArgs.push_back("-O1"); |
| 420 | else |
Daniel Dunbar | 5697aa0 | 2009-03-18 23:39:35 +0000 | [diff] [blame] | 421 | A->render(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Daniel Dunbar | 06ef3c3 | 2009-04-16 03:44:10 +0000 | [diff] [blame] | 424 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 425 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 426 | |
| 427 | // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi} |
| 428 | // (-ansi is equivalent to -std=c89). |
| 429 | // |
| 430 | // If a std is supplied, only add -trigraphs if it follows the |
| 431 | // option. |
| 432 | if (Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { |
| 433 | if (Std->getOption().matches(options::OPT_ansi)) |
| 434 | CmdArgs.push_back("-std=c89"); |
| 435 | else |
| 436 | Std->render(Args, CmdArgs); |
| 437 | |
| 438 | if (Arg *A = Args.getLastArg(options::OPT_trigraphs)) |
| 439 | if (A->getIndex() > Std->getIndex()) |
| 440 | A->render(Args, CmdArgs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 441 | } else { |
| 442 | // Honor -std-default. |
| 443 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, |
| 444 | "-std=", /*Joined=*/true); |
Daniel Dunbar | d573d26 | 2009-04-07 22:13:21 +0000 | [diff] [blame] | 445 | Args.AddLastArg(CmdArgs, options::OPT_trigraphs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 446 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 447 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 448 | if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) { |
| 449 | CmdArgs.push_back("-ftemplate-depth"); |
| 450 | CmdArgs.push_back(A->getValue(Args)); |
| 451 | } |
| 452 | |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 453 | // Forward -f options which we can pass directly. |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 454 | Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); |
| 455 | Args.AddLastArg(CmdArgs, options::OPT_fexceptions); |
| 456 | Args.AddLastArg(CmdArgs, options::OPT_ffreestanding); |
| 457 | Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); |
| 458 | Args.AddLastArg(CmdArgs, options::OPT_fgnu_runtime); |
| 459 | Args.AddLastArg(CmdArgs, options::OPT_flax_vector_conversions); |
| 460 | Args.AddLastArg(CmdArgs, options::OPT_fms_extensions); |
| 461 | Args.AddLastArg(CmdArgs, options::OPT_fnext_runtime); |
| 462 | Args.AddLastArg(CmdArgs, options::OPT_fno_caret_diagnostics); |
| 463 | Args.AddLastArg(CmdArgs, options::OPT_fno_show_column); |
| 464 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc_only); |
| 465 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc); |
| 466 | // FIXME: Should we remove this? |
| 467 | Args.AddLastArg(CmdArgs, options::OPT_fobjc_nonfragile_abi); |
| 468 | Args.AddLastArg(CmdArgs, options::OPT_fprint_source_range_info); |
Chris Lattner | 182e092 | 2009-04-21 05:34:31 +0000 | [diff] [blame] | 469 | Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info); |
Daniel Dunbar | 3aaf082 | 2009-04-07 21:51:40 +0000 | [diff] [blame] | 470 | Args.AddLastArg(CmdArgs, options::OPT_ftime_report); |
| 471 | Args.AddLastArg(CmdArgs, options::OPT_ftrapv); |
| 472 | Args.AddLastArg(CmdArgs, options::OPT_fvisibility_EQ); |
| 473 | Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 474 | |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 475 | // Forward -f options with positive and negative forms; we translate |
| 476 | // these by hand. |
| 477 | |
| 478 | // -fbuiltin is default, only pass non-default. |
| 479 | if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin)) |
| 480 | CmdArgs.push_back("-fbuiltin=0"); |
| 481 | |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 482 | // -fblocks default varies depending on platform and language; only |
| 483 | // pass if specified. |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 484 | if (Arg *A = Args.getLastArg(options::OPT_fblocks, options::OPT_fno_blocks)) { |
| 485 | if (A->getOption().matches(options::OPT_fblocks)) |
| 486 | CmdArgs.push_back("-fblocks"); |
| 487 | else |
| 488 | CmdArgs.push_back("-fblocks=0"); |
| 489 | } |
| 490 | |
Daniel Dunbar | 82d0068 | 2009-04-07 23:51:44 +0000 | [diff] [blame] | 491 | // -fno-pascal-strings is default, only pass non-default. If the |
| 492 | // -tool chain happened to translate to -mpascal-strings, we want to |
| 493 | // -back translate here. |
| 494 | // |
| 495 | // FIXME: This is gross; that translation should be pulled from the |
| 496 | // tool chain. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 497 | if (Args.hasFlag(options::OPT_fpascal_strings, |
Daniel Dunbar | 82d0068 | 2009-04-07 23:51:44 +0000 | [diff] [blame] | 498 | options::OPT_fno_pascal_strings, |
| 499 | false) || |
| 500 | Args.hasFlag(options::OPT_mpascal_strings, |
| 501 | options::OPT_mno_pascal_strings, |
| 502 | false)) |
Daniel Dunbar | 48d1ef7 | 2009-04-07 21:16:11 +0000 | [diff] [blame] | 503 | CmdArgs.push_back("-fpascal-strings"); |
| 504 | |
| 505 | // -fcommon is default, only pass non-default. |
| 506 | if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common)) |
| 507 | CmdArgs.push_back("-fno-common"); |
| 508 | |
Daniel Dunbar | 70d3c92 | 2009-04-15 02:37:43 +0000 | [diff] [blame] | 509 | // -fsigned-bitfields is default, and clang doesn't yet support |
| 510 | // --funsigned-bitfields. |
| 511 | if (!Args.hasFlag(options::OPT_fsigned_bitfields, |
| 512 | options::OPT_funsigned_bitfields)) |
| 513 | D.Diag(clang::diag::warn_drv_clang_unsupported) |
| 514 | << Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args); |
| 515 | |
Daniel Dunbar | 49138fc | 2009-04-19 21:09:34 +0000 | [diff] [blame] | 516 | // -fdiagnostics-fixit-info is default, only pass non-default. |
| 517 | if (!Args.hasFlag(options::OPT_fdiagnostics_fixit_info, |
| 518 | options::OPT_fno_diagnostics_fixit_info)) |
| 519 | CmdArgs.push_back("-fno-diagnostics-fixit-info"); |
| 520 | |
Daniel Dunbar | 9e820ee | 2009-04-16 06:32:38 +0000 | [diff] [blame] | 521 | // Enable -fdiagnostics-show-option by default. |
| 522 | if (Args.hasFlag(options::OPT_fdiagnostics_show_option, |
| 523 | options::OPT_fno_diagnostics_show_option)) |
| 524 | CmdArgs.push_back("-fdiagnostics-show-option"); |
| 525 | |
Daniel Dunbar | 7695fba | 2009-04-19 21:20:32 +0000 | [diff] [blame] | 526 | // -fdollars-in-identifiers default varies depending on platform and |
| 527 | // language; only pass if specified. |
| 528 | if (Arg *A = Args.getLastArg(options::OPT_fdollars_in_identifiers, |
| 529 | options::OPT_fno_dollars_in_identifiers)) { |
| 530 | if (A->getOption().matches(options::OPT_fdollars_in_identifiers)) |
| 531 | CmdArgs.push_back("-fdollars-in-identifiers=1"); |
| 532 | else |
| 533 | CmdArgs.push_back("-fdollars-in-identifiers=0"); |
| 534 | } |
| 535 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 536 | Args.AddLastArg(CmdArgs, options::OPT_dM); |
Chris Lattner | d82df3a | 2009-04-12 01:56:53 +0000 | [diff] [blame] | 537 | Args.AddLastArg(CmdArgs, options::OPT_dD); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 538 | |
| 539 | Args.AddAllArgValues(CmdArgs, options::OPT_Xclang); |
| 540 | |
Daniel Dunbar | cd8e4c4 | 2009-03-30 06:36:42 +0000 | [diff] [blame] | 541 | if (Output.getType() == types::TY_Dependencies) { |
| 542 | // Handled with other dependency code. |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 543 | } else if (Output.isPipe()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 544 | CmdArgs.push_back("-o"); |
| 545 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 546 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 547 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 548 | CmdArgs.push_back(Output.getFilename()); |
| 549 | } else { |
| 550 | assert(Output.isNothing() && "Invalid output."); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 553 | for (InputInfoList::const_iterator |
| 554 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 555 | const InputInfo &II = *it; |
| 556 | CmdArgs.push_back("-x"); |
| 557 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 558 | if (II.isPipe()) |
| 559 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 560 | else if (II.isFilename()) |
| 561 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 562 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 563 | II.getInputArg().renderAsInput(Args, CmdArgs); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 564 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 565 | |
| 566 | const char *Exec = |
Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 567 | Args.MakeArgString(getToolChain().GetProgramPath(C, "clang-cc").c_str()); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 568 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 569 | |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 570 | // Explicitly warn that these options are unsupported, even though |
| 571 | // we are allowing compilation to continue. |
| 572 | // FIXME: Use iterator. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 573 | for (ArgList::const_iterator |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 574 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 575 | const Arg *A = *it; |
| 576 | if (A->getOption().matches(options::OPT_pg)) { |
| 577 | A->claim(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 578 | D.Diag(clang::diag::warn_drv_clang_unsupported) |
Daniel Dunbar | 5c1aaaf | 2009-04-07 19:18:24 +0000 | [diff] [blame] | 579 | << A->getAsString(Args); |
| 580 | } |
| 581 | } |
| 582 | |
Daniel Dunbar | 68fb469 | 2009-04-03 20:51:31 +0000 | [diff] [blame] | 583 | // Claim some arguments which clang supports automatically. |
| 584 | |
| 585 | // -fpch-preprocess is used with gcc to add a special marker in the |
| 586 | // -output to include the PCH file. Clang's PTH solution is |
| 587 | // -completely transparent, so we do not need to deal with it at |
| 588 | // -all. |
| 589 | Args.ClaimAllArgs(options::OPT_fpch_preprocess); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 590 | |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 591 | // Claim some arguments which clang doesn't support, but we don't |
| 592 | // care to warn the user about. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 593 | |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 594 | // FIXME: Use iterator. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 595 | for (ArgList::const_iterator |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 596 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
| 597 | const Arg *A = *it; |
Daniel Dunbar | 06ef3c3 | 2009-04-16 03:44:10 +0000 | [diff] [blame] | 598 | if (A->getOption().matches(options::OPT_clang_ignored_f_Group) || |
Daniel Dunbar | 16fd3a9 | 2009-04-07 02:59:27 +0000 | [diff] [blame] | 599 | A->getOption().matches(options::OPT_clang_ignored_m_Group)) |
Daniel Dunbar | a880db0 | 2009-03-23 19:03:36 +0000 | [diff] [blame] | 600 | A->claim(); |
| 601 | } |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 604 | void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, |
| 605 | Job &Dest, |
| 606 | const InputInfo &Output, |
| 607 | const InputInfoList &Inputs, |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 608 | const ArgList &Args, |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 609 | const char *LinkingOutput) const { |
| 610 | ArgStringList CmdArgs; |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 611 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 612 | for (ArgList::const_iterator |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 613 | it = Args.begin(), ie = Args.end(); it != ie; ++it) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 614 | Arg *A = *it; |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 615 | if (A->getOption().hasForwardToGCC()) { |
| 616 | // It is unfortunate that we have to claim here, as this means |
| 617 | // we will basically never report anything interesting for |
| 618 | // platforms using a generic gcc. |
| 619 | A->claim(); |
Daniel Dunbar | 1d46033 | 2009-03-18 10:01:51 +0000 | [diff] [blame] | 620 | A->render(Args, CmdArgs); |
Daniel Dunbar | 7587719 | 2009-03-19 07:55:12 +0000 | [diff] [blame] | 621 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 622 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 623 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 624 | RenderExtraToolArgs(CmdArgs); |
| 625 | |
| 626 | // If using a driver driver, force the arch. |
| 627 | if (getToolChain().getHost().useDriverDriver()) { |
| 628 | CmdArgs.push_back("-arch"); |
Daniel Dunbar | bf54a06 | 2009-04-01 20:33:11 +0000 | [diff] [blame] | 629 | |
| 630 | // FIXME: Remove these special cases. |
| 631 | const char *Str = getToolChain().getArchName().c_str(); |
| 632 | if (strcmp(Str, "powerpc") == 0) |
| 633 | Str = "ppc"; |
| 634 | else if (strcmp(Str, "powerpc64") == 0) |
| 635 | Str = "ppc64"; |
| 636 | CmdArgs.push_back(Str); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | if (Output.isPipe()) { |
| 640 | CmdArgs.push_back("-o"); |
| 641 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 642 | } else if (Output.isFilename()) { |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 643 | CmdArgs.push_back("-o"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 644 | CmdArgs.push_back(Output.getFilename()); |
| 645 | } else { |
| 646 | assert(Output.isNothing() && "Unexpected output"); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 647 | CmdArgs.push_back("-fsyntax-only"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 648 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 649 | |
| 650 | |
| 651 | // Only pass -x if gcc will understand it; otherwise hope gcc |
| 652 | // understands the suffix correctly. The main use case this would go |
| 653 | // wrong in is for linker inputs if they happened to have an odd |
| 654 | // suffix; really the only way to get this to happen is a command |
| 655 | // like '-x foobar a.c' which will treat a.c like a linker input. |
| 656 | // |
| 657 | // FIXME: For the linker case specifically, can we safely convert |
| 658 | // inputs into '-Wl,' options? |
| 659 | for (InputInfoList::const_iterator |
| 660 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 661 | const InputInfo &II = *it; |
| 662 | if (types::canTypeBeUserSpecified(II.getType())) { |
| 663 | CmdArgs.push_back("-x"); |
| 664 | CmdArgs.push_back(types::getTypeName(II.getType())); |
| 665 | } |
| 666 | |
| 667 | if (II.isPipe()) |
| 668 | CmdArgs.push_back("-"); |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 669 | else if (II.isFilename()) |
| 670 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 671 | else |
Daniel Dunbar | 115a792 | 2009-03-19 07:29:38 +0000 | [diff] [blame] | 672 | // Don't render as input, we need gcc to do the translations. |
| 673 | II.getInputArg().render(Args, CmdArgs); |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 676 | const char *GCCName = |
Daniel Dunbar | 78d8a08 | 2009-04-01 23:34:41 +0000 | [diff] [blame] | 677 | getToolChain().getHost().getDriver().CCCGenericGCCName.c_str(); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 678 | const char *Exec = |
Daniel Dunbar | 78d8a08 | 2009-04-01 23:34:41 +0000 | [diff] [blame] | 679 | Args.MakeArgString(getToolChain().GetProgramPath(C, GCCName).c_str()); |
Daniel Dunbar | 632f50e | 2009-03-18 21:34:08 +0000 | [diff] [blame] | 680 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 681 | } |
| 682 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 683 | void gcc::Preprocess::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 684 | CmdArgs.push_back("-E"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 687 | void gcc::Precompile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 688 | // The type is good enough. |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 691 | void gcc::Compile::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 692 | CmdArgs.push_back("-S"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 695 | void gcc::Assemble::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 696 | CmdArgs.push_back("-c"); |
Daniel Dunbar | 47ac7d2 | 2009-03-18 06:00:36 +0000 | [diff] [blame] | 697 | } |
Daniel Dunbar | b488c1d | 2009-03-18 08:07:30 +0000 | [diff] [blame] | 698 | |
| 699 | void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const { |
| 700 | // The types are (hopefully) good enough. |
| 701 | } |
| 702 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 703 | const char *darwin::CC1::getCC1Name(types::ID Type) const { |
| 704 | switch (Type) { |
| 705 | default: |
| 706 | assert(0 && "Unexpected type for Darwin CC1 tool."); |
| 707 | case types::TY_Asm: |
| 708 | case types::TY_C: case types::TY_CHeader: |
| 709 | case types::TY_PP_C: case types::TY_PP_CHeader: |
| 710 | return "cc1"; |
| 711 | case types::TY_ObjC: case types::TY_ObjCHeader: |
| 712 | case types::TY_PP_ObjC: case types::TY_PP_ObjCHeader: |
| 713 | return "cc1obj"; |
| 714 | case types::TY_CXX: case types::TY_CXXHeader: |
| 715 | case types::TY_PP_CXX: case types::TY_PP_CXXHeader: |
| 716 | return "cc1plus"; |
| 717 | case types::TY_ObjCXX: case types::TY_ObjCXXHeader: |
| 718 | case types::TY_PP_ObjCXX: case types::TY_PP_ObjCXXHeader: |
| 719 | return "cc1objplus"; |
| 720 | } |
| 721 | } |
| 722 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 723 | const char *darwin::CC1::getBaseInputName(const ArgList &Args, |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 724 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 725 | llvm::sys::Path P(Inputs[0].getBaseInput()); |
| 726 | return Args.MakeArgString(P.getLast().c_str()); |
| 727 | } |
| 728 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 729 | const char *darwin::CC1::getBaseInputStem(const ArgList &Args, |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 730 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 731 | const char *Str = getBaseInputName(Args, Inputs); |
| 732 | |
| 733 | if (const char *End = strchr(Str, '.')) |
| 734 | return Args.MakeArgString(std::string(Str, End).c_str()); |
| 735 | |
| 736 | return Str; |
| 737 | } |
| 738 | |
| 739 | const char * |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 740 | darwin::CC1::getDependencyFileName(const ArgList &Args, |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 741 | const InputInfoList &Inputs) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 742 | // FIXME: Think about this more. |
| 743 | std::string Res; |
| 744 | |
| 745 | if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) { |
| 746 | std::string Str(OutputOpt->getValue(Args)); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 747 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 748 | Res = Str.substr(0, Str.rfind('.')); |
| 749 | } else |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 750 | Res = darwin::CC1::getBaseInputStem(Args, Inputs); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 751 | |
| 752 | return Args.MakeArgString((Res + ".d").c_str()); |
| 753 | } |
| 754 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 755 | void darwin::CC1::AddCC1Args(const ArgList &Args, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 756 | ArgStringList &CmdArgs) const { |
| 757 | // Derived from cc1 spec. |
| 758 | |
| 759 | // FIXME: -fapple-kext seems to disable this too. Investigate. |
| 760 | if (!Args.hasArg(options::OPT_mkernel) && !Args.hasArg(options::OPT_static) && |
| 761 | !Args.hasArg(options::OPT_mdynamic_no_pic)) |
| 762 | CmdArgs.push_back("-fPIC"); |
| 763 | |
| 764 | // gcc has some code here to deal with when no -mmacosx-version-min |
| 765 | // and no -miphoneos-version-min is present, but this never happens |
| 766 | // due to tool chain specific argument translation. |
| 767 | |
| 768 | // FIXME: Remove mthumb |
| 769 | // FIXME: Remove mno-thumb |
| 770 | // FIXME: Remove faltivec |
| 771 | // FIXME: Remove mno-fused-madd |
| 772 | // FIXME: Remove mlong-branch |
| 773 | // FIXME: Remove mlongcall |
| 774 | // FIXME: Remove mcpu=G4 |
| 775 | // FIXME: Remove mcpu=G5 |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 776 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 777 | if (Args.hasArg(options::OPT_g_Flag) && |
| 778 | !Args.hasArg(options::OPT_fno_eliminate_unused_debug_symbols)) |
| 779 | CmdArgs.push_back("-feliminate-unused-debug-symbols"); |
| 780 | } |
| 781 | |
| 782 | void darwin::CC1::AddCC1OptionsArgs(const ArgList &Args, ArgStringList &CmdArgs, |
| 783 | const InputInfoList &Inputs, |
| 784 | const ArgStringList &OutputArgs) const { |
| 785 | const Driver &D = getToolChain().getHost().getDriver(); |
| 786 | |
| 787 | // Derived from cc1_options spec. |
| 788 | if (Args.hasArg(options::OPT_fast) || |
| 789 | Args.hasArg(options::OPT_fastf) || |
| 790 | Args.hasArg(options::OPT_fastcp)) |
| 791 | CmdArgs.push_back("-O3"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 792 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 793 | if (Arg *A = Args.getLastArg(options::OPT_pg)) |
| 794 | if (Args.hasArg(options::OPT_fomit_frame_pointer)) |
| 795 | D.Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 796 | << A->getAsString(Args) << "-fomit-frame-pointer"; |
| 797 | |
| 798 | AddCC1Args(Args, CmdArgs); |
| 799 | |
| 800 | if (!Args.hasArg(options::OPT_Q)) |
| 801 | CmdArgs.push_back("-quiet"); |
| 802 | |
| 803 | CmdArgs.push_back("-dumpbase"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 804 | CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 805 | |
| 806 | Args.AddAllArgs(CmdArgs, options::OPT_d_Group); |
| 807 | |
| 808 | Args.AddAllArgs(CmdArgs, options::OPT_m_Group); |
| 809 | Args.AddAllArgs(CmdArgs, options::OPT_a_Group); |
| 810 | |
| 811 | // FIXME: The goal is to use the user provided -o if that is our |
| 812 | // final output, otherwise to drive from the original input |
| 813 | // name. Find a clean way to go about this. |
| 814 | if ((Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) && |
| 815 | Args.hasArg(options::OPT_o)) { |
| 816 | Arg *OutputOpt = Args.getLastArg(options::OPT_o); |
| 817 | CmdArgs.push_back("-auxbase-strip"); |
| 818 | CmdArgs.push_back(OutputOpt->getValue(Args)); |
| 819 | } else { |
| 820 | CmdArgs.push_back("-auxbase"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 821 | CmdArgs.push_back(darwin::CC1::getBaseInputStem(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | Args.AddAllArgs(CmdArgs, options::OPT_g_Group); |
| 825 | |
| 826 | Args.AddAllArgs(CmdArgs, options::OPT_O); |
| 827 | // FIXME: -Wall is getting some special treatment. Investigate. |
| 828 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group); |
| 829 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 830 | Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 831 | options::OPT_trigraphs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 832 | if (!Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { |
| 833 | // Honor -std-default. |
| 834 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, |
| 835 | "-std=", /*Joined=*/true); |
| 836 | } |
| 837 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 838 | if (Args.hasArg(options::OPT_v)) |
| 839 | CmdArgs.push_back("-version"); |
| 840 | if (Args.hasArg(options::OPT_pg)) |
| 841 | CmdArgs.push_back("-p"); |
| 842 | Args.AddLastArg(CmdArgs, options::OPT_p); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 843 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 844 | // The driver treats -fsyntax-only specially. |
| 845 | Args.AddAllArgs(CmdArgs, options::OPT_f_Group, options::OPT_fsyntax_only); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 846 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 847 | Args.AddAllArgs(CmdArgs, options::OPT_undef); |
| 848 | if (Args.hasArg(options::OPT_Qn)) |
| 849 | CmdArgs.push_back("-fno-ident"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 850 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 851 | // FIXME: This isn't correct. |
| 852 | //Args.AddLastArg(CmdArgs, options::OPT__help) |
| 853 | //Args.AddLastArg(CmdArgs, options::OPT__targetHelp) |
| 854 | |
| 855 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 856 | |
| 857 | // FIXME: Still don't get what is happening here. Investigate. |
| 858 | Args.AddAllArgs(CmdArgs, options::OPT__param); |
| 859 | |
| 860 | if (Args.hasArg(options::OPT_fmudflap) || |
| 861 | Args.hasArg(options::OPT_fmudflapth)) { |
| 862 | CmdArgs.push_back("-fno-builtin"); |
| 863 | CmdArgs.push_back("-fno-merge-constants"); |
| 864 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 865 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 866 | if (Args.hasArg(options::OPT_coverage)) { |
| 867 | CmdArgs.push_back("-fprofile-arcs"); |
| 868 | CmdArgs.push_back("-ftest-coverage"); |
| 869 | } |
| 870 | |
| 871 | if (types::isCXX(Inputs[0].getType())) |
| 872 | CmdArgs.push_back("-D__private_extern__=extern"); |
| 873 | } |
| 874 | |
| 875 | void darwin::CC1::AddCPPOptionsArgs(const ArgList &Args, ArgStringList &CmdArgs, |
| 876 | const InputInfoList &Inputs, |
| 877 | const ArgStringList &OutputArgs) const { |
| 878 | // Derived from cpp_options |
| 879 | AddCPPUniqueOptionsArgs(Args, CmdArgs, Inputs); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 880 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 881 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 882 | |
| 883 | AddCC1Args(Args, CmdArgs); |
| 884 | |
| 885 | // NOTE: The code below has some commonality with cpp_options, but |
| 886 | // in classic gcc style ends up sending things in different |
| 887 | // orders. This may be a good merge candidate once we drop pedantic |
| 888 | // compatibility. |
| 889 | |
| 890 | Args.AddAllArgs(CmdArgs, options::OPT_m_Group); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 891 | Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 892 | options::OPT_trigraphs); |
Daniel Dunbar | a3ff202 | 2009-04-26 01:10:38 +0000 | [diff] [blame] | 893 | if (!Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) { |
| 894 | // Honor -std-default. |
| 895 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ, |
| 896 | "-std=", /*Joined=*/true); |
| 897 | } |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 898 | Args.AddAllArgs(CmdArgs, options::OPT_W_Group, options::OPT_pedantic_Group); |
| 899 | Args.AddLastArg(CmdArgs, options::OPT_w); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 900 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 901 | // The driver treats -fsyntax-only specially. |
| 902 | Args.AddAllArgs(CmdArgs, options::OPT_f_Group, options::OPT_fsyntax_only); |
| 903 | |
| 904 | if (Args.hasArg(options::OPT_g_Group) && !Args.hasArg(options::OPT_g0) && |
| 905 | !Args.hasArg(options::OPT_fno_working_directory)) |
| 906 | CmdArgs.push_back("-fworking-directory"); |
| 907 | |
| 908 | Args.AddAllArgs(CmdArgs, options::OPT_O); |
| 909 | Args.AddAllArgs(CmdArgs, options::OPT_undef); |
| 910 | if (Args.hasArg(options::OPT_save_temps)) |
| 911 | CmdArgs.push_back("-fpch-preprocess"); |
| 912 | } |
| 913 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 914 | void darwin::CC1::AddCPPUniqueOptionsArgs(const ArgList &Args, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 915 | ArgStringList &CmdArgs, |
| 916 | const InputInfoList &Inputs) const |
| 917 | { |
| 918 | const Driver &D = getToolChain().getHost().getDriver(); |
| 919 | |
| 920 | // Derived from cpp_unique_options. |
| 921 | Arg *A; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 922 | if ((A = Args.getLastArg(options::OPT_C)) || |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 923 | (A = Args.getLastArg(options::OPT_CC))) { |
| 924 | if (!Args.hasArg(options::OPT_E)) |
| 925 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 926 | << A->getAsString(Args) << "-E"; |
| 927 | } |
| 928 | if (!Args.hasArg(options::OPT_Q)) |
| 929 | CmdArgs.push_back("-quiet"); |
| 930 | Args.AddAllArgs(CmdArgs, options::OPT_nostdinc); |
| 931 | Args.AddLastArg(CmdArgs, options::OPT_v); |
| 932 | Args.AddAllArgs(CmdArgs, options::OPT_I_Group, options::OPT_F); |
| 933 | Args.AddLastArg(CmdArgs, options::OPT_P); |
| 934 | |
| 935 | // FIXME: Handle %I properly. |
| 936 | if (getToolChain().getArchName() == "x86_64") { |
| 937 | CmdArgs.push_back("-imultilib"); |
| 938 | CmdArgs.push_back("x86_64"); |
| 939 | } |
| 940 | |
| 941 | if (Args.hasArg(options::OPT_MD)) { |
| 942 | CmdArgs.push_back("-MD"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 943 | CmdArgs.push_back(darwin::CC1::getDependencyFileName(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | if (Args.hasArg(options::OPT_MMD)) { |
| 947 | CmdArgs.push_back("-MMD"); |
Daniel Dunbar | a5a7bd0 | 2009-03-30 00:34:04 +0000 | [diff] [blame] | 948 | CmdArgs.push_back(darwin::CC1::getDependencyFileName(Args, Inputs)); |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | Args.AddLastArg(CmdArgs, options::OPT_M); |
| 952 | Args.AddLastArg(CmdArgs, options::OPT_MM); |
| 953 | Args.AddAllArgs(CmdArgs, options::OPT_MF); |
| 954 | Args.AddLastArg(CmdArgs, options::OPT_MG); |
| 955 | Args.AddLastArg(CmdArgs, options::OPT_MP); |
| 956 | Args.AddAllArgs(CmdArgs, options::OPT_MQ); |
| 957 | Args.AddAllArgs(CmdArgs, options::OPT_MT); |
| 958 | if (!Args.hasArg(options::OPT_M) && !Args.hasArg(options::OPT_MM) && |
| 959 | (Args.hasArg(options::OPT_MD) || Args.hasArg(options::OPT_MMD))) { |
| 960 | if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) { |
| 961 | CmdArgs.push_back("-MQ"); |
| 962 | CmdArgs.push_back(OutputOpt->getValue(Args)); |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | Args.AddLastArg(CmdArgs, options::OPT_remap); |
| 967 | if (Args.hasArg(options::OPT_g3)) |
| 968 | CmdArgs.push_back("-dD"); |
| 969 | Args.AddLastArg(CmdArgs, options::OPT_H); |
| 970 | |
| 971 | AddCPPArgs(Args, CmdArgs); |
| 972 | |
| 973 | Args.AddAllArgs(CmdArgs, options::OPT_D, options::OPT_U, options::OPT_A); |
| 974 | Args.AddAllArgs(CmdArgs, options::OPT_i_Group); |
| 975 | |
| 976 | for (InputInfoList::const_iterator |
| 977 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 978 | const InputInfo &II = *it; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 979 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 980 | if (II.isPipe()) |
| 981 | CmdArgs.push_back("-"); |
| 982 | else |
| 983 | CmdArgs.push_back(II.getFilename()); |
| 984 | } |
| 985 | |
| 986 | Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA, |
| 987 | options::OPT_Xpreprocessor); |
| 988 | |
| 989 | if (Args.hasArg(options::OPT_fmudflap)) { |
| 990 | CmdArgs.push_back("-D_MUDFLAP"); |
| 991 | CmdArgs.push_back("-include"); |
| 992 | CmdArgs.push_back("mf-runtime.h"); |
| 993 | } |
| 994 | |
| 995 | if (Args.hasArg(options::OPT_fmudflapth)) { |
| 996 | CmdArgs.push_back("-D_MUDFLAP"); |
| 997 | CmdArgs.push_back("-D_MUDFLAPTH"); |
| 998 | CmdArgs.push_back("-include"); |
| 999 | CmdArgs.push_back("mf-runtime.h"); |
| 1000 | } |
| 1001 | } |
| 1002 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1003 | void darwin::CC1::AddCPPArgs(const ArgList &Args, |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1004 | ArgStringList &CmdArgs) const { |
| 1005 | // Derived from cpp spec. |
| 1006 | |
| 1007 | if (Args.hasArg(options::OPT_static)) { |
| 1008 | // The gcc spec is broken here, it refers to dynamic but |
| 1009 | // that has been translated. Start by being bug compatible. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1010 | |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1011 | // if (!Args.hasArg(arglist.parser.dynamicOption)) |
| 1012 | CmdArgs.push_back("-D__STATIC__"); |
| 1013 | } else |
| 1014 | CmdArgs.push_back("-D__DYNAMIC__"); |
| 1015 | |
| 1016 | if (Args.hasArg(options::OPT_pthread)) |
| 1017 | CmdArgs.push_back("-D_REENTRANT"); |
| 1018 | } |
| 1019 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1020 | void darwin::Preprocess::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1021 | Job &Dest, const InputInfo &Output, |
| 1022 | const InputInfoList &Inputs, |
| 1023 | const ArgList &Args, |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1024 | const char *LinkingOutput) const { |
| 1025 | ArgStringList CmdArgs; |
| 1026 | |
| 1027 | assert(Inputs.size() == 1 && "Unexpected number of inputs!"); |
| 1028 | |
| 1029 | CmdArgs.push_back("-E"); |
| 1030 | |
| 1031 | if (Args.hasArg(options::OPT_traditional) || |
| 1032 | Args.hasArg(options::OPT_ftraditional) || |
| 1033 | Args.hasArg(options::OPT_traditional_cpp)) |
| 1034 | CmdArgs.push_back("-traditional-cpp"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1035 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1036 | ArgStringList OutputArgs; |
| 1037 | if (Output.isFilename()) { |
| 1038 | OutputArgs.push_back("-o"); |
| 1039 | OutputArgs.push_back(Output.getFilename()); |
| 1040 | } else { |
| 1041 | assert(Output.isPipe() && "Unexpected CC1 output."); |
| 1042 | } |
| 1043 | |
Daniel Dunbar | 9120f17 | 2009-03-29 22:27:40 +0000 | [diff] [blame] | 1044 | if (Args.hasArg(options::OPT_E)) { |
| 1045 | AddCPPOptionsArgs(Args, CmdArgs, Inputs, OutputArgs); |
| 1046 | } else { |
| 1047 | AddCPPOptionsArgs(Args, CmdArgs, Inputs, ArgStringList()); |
| 1048 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 1049 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1050 | |
Daniel Dunbar | 8a2073a | 2009-04-03 01:27:06 +0000 | [diff] [blame] | 1051 | Args.AddAllArgs(CmdArgs, options::OPT_d_Group); |
| 1052 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1053 | const char *CC1Name = getCC1Name(Inputs[0].getType()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1054 | const char *Exec = |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1055 | Args.MakeArgString(getToolChain().GetProgramPath(C, CC1Name).c_str()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1056 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | void darwin::Compile::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1060 | Job &Dest, const InputInfo &Output, |
| 1061 | const InputInfoList &Inputs, |
| 1062 | const ArgList &Args, |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1063 | const char *LinkingOutput) const { |
| 1064 | const Driver &D = getToolChain().getHost().getDriver(); |
| 1065 | ArgStringList CmdArgs; |
| 1066 | |
| 1067 | assert(Inputs.size() == 1 && "Unexpected number of inputs!"); |
| 1068 | |
| 1069 | types::ID InputType = Inputs[0].getType(); |
| 1070 | const Arg *A; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1071 | if ((A = Args.getLastArg(options::OPT_traditional)) || |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1072 | (A = Args.getLastArg(options::OPT_ftraditional))) |
| 1073 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 1074 | << A->getAsString(Args) << "-E"; |
| 1075 | |
| 1076 | if (Output.getType() == types::TY_LLVMAsm) |
| 1077 | CmdArgs.push_back("-emit-llvm"); |
| 1078 | else if (Output.getType() == types::TY_LLVMBC) |
| 1079 | CmdArgs.push_back("-emit-llvm-bc"); |
| 1080 | |
| 1081 | ArgStringList OutputArgs; |
| 1082 | if (Output.getType() != types::TY_PCH) { |
| 1083 | OutputArgs.push_back("-o"); |
| 1084 | if (Output.isPipe()) |
| 1085 | OutputArgs.push_back("-"); |
| 1086 | else if (Output.isNothing()) |
| 1087 | OutputArgs.push_back("/dev/null"); |
| 1088 | else |
| 1089 | OutputArgs.push_back(Output.getFilename()); |
| 1090 | } |
| 1091 | |
| 1092 | // There is no need for this level of compatibility, but it makes |
| 1093 | // diffing easier. |
| 1094 | bool OutputArgsEarly = (Args.hasArg(options::OPT_fsyntax_only) || |
| 1095 | Args.hasArg(options::OPT_S)); |
| 1096 | |
| 1097 | if (types::getPreprocessedType(InputType) != types::TY_INVALID) { |
Daniel Dunbar | a3ec60e | 2009-03-29 18:40:18 +0000 | [diff] [blame] | 1098 | AddCPPUniqueOptionsArgs(Args, CmdArgs, Inputs); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1099 | if (OutputArgsEarly) { |
| 1100 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, OutputArgs); |
| 1101 | } else { |
| 1102 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, ArgStringList()); |
| 1103 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 1104 | } |
| 1105 | } else { |
| 1106 | CmdArgs.push_back("-fpreprocessed"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1107 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1108 | // FIXME: There is a spec command to remove |
| 1109 | // -fpredictive-compilation args here. Investigate. |
| 1110 | |
| 1111 | for (InputInfoList::const_iterator |
| 1112 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1113 | const InputInfo &II = *it; |
| 1114 | |
| 1115 | if (II.isPipe()) |
| 1116 | CmdArgs.push_back("-"); |
| 1117 | else |
| 1118 | CmdArgs.push_back(II.getFilename()); |
| 1119 | } |
| 1120 | |
| 1121 | if (OutputArgsEarly) { |
| 1122 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, OutputArgs); |
| 1123 | } else { |
| 1124 | AddCC1OptionsArgs(Args, CmdArgs, Inputs, ArgStringList()); |
| 1125 | CmdArgs.append(OutputArgs.begin(), OutputArgs.end()); |
| 1126 | } |
| 1127 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1128 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1129 | if (Output.getType() == types::TY_PCH) { |
| 1130 | assert(Output.isFilename() && "Invalid PCH output."); |
| 1131 | |
| 1132 | CmdArgs.push_back("-o"); |
| 1133 | // NOTE: gcc uses a temp .s file for this, but there doesn't seem |
| 1134 | // to be a good reason. |
| 1135 | CmdArgs.push_back("/dev/null"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1136 | |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1137 | CmdArgs.push_back("--output-pch="); |
| 1138 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1139 | } |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1140 | |
| 1141 | const char *CC1Name = getCC1Name(Inputs[0].getType()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1142 | const char *Exec = |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1143 | Args.MakeArgString(getToolChain().GetProgramPath(C, CC1Name).c_str()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1144 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | 40f1265 | 2009-03-29 17:08:39 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1147 | void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1148 | Job &Dest, const InputInfo &Output, |
| 1149 | const InputInfoList &Inputs, |
| 1150 | const ArgList &Args, |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1151 | const char *LinkingOutput) const { |
| 1152 | ArgStringList CmdArgs; |
| 1153 | |
| 1154 | assert(Inputs.size() == 1 && "Unexpected number of inputs."); |
| 1155 | const InputInfo &Input = Inputs[0]; |
| 1156 | |
| 1157 | // Bit of a hack, this is only used for original inputs. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1158 | // |
Daniel Dunbar | 8e4fea6 | 2009-04-01 00:27:44 +0000 | [diff] [blame] | 1159 | // FIXME: This is broken for preprocessed .s inputs. |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1160 | if (Input.isFilename() && |
Daniel Dunbar | 8e4fea6 | 2009-04-01 00:27:44 +0000 | [diff] [blame] | 1161 | strcmp(Input.getFilename(), Input.getBaseInput()) == 0) { |
| 1162 | if (Args.hasArg(options::OPT_gstabs)) |
| 1163 | CmdArgs.push_back("--gstabs"); |
| 1164 | else if (Args.hasArg(options::OPT_g_Group)) |
| 1165 | CmdArgs.push_back("--gdwarf2"); |
| 1166 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1167 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1168 | // Derived from asm spec. |
| 1169 | CmdArgs.push_back("-arch"); |
| 1170 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 1171 | |
| 1172 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
| 1173 | if ((Args.hasArg(options::OPT_mkernel) || |
| 1174 | Args.hasArg(options::OPT_static) || |
| 1175 | Args.hasArg(options::OPT_fapple_kext)) && |
| 1176 | !Args.hasArg(options::OPT_dynamic)) |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1177 | CmdArgs.push_back("-static"); |
| 1178 | |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1179 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 1180 | options::OPT_Xassembler); |
| 1181 | |
| 1182 | assert(Output.isFilename() && "Unexpected lipo output."); |
| 1183 | CmdArgs.push_back("-o"); |
| 1184 | CmdArgs.push_back(Output.getFilename()); |
| 1185 | |
| 1186 | if (Input.isPipe()) { |
| 1187 | CmdArgs.push_back("-"); |
| 1188 | } else { |
| 1189 | assert(Input.isFilename() && "Invalid input."); |
| 1190 | CmdArgs.push_back(Input.getFilename()); |
| 1191 | } |
| 1192 | |
| 1193 | // asm_final spec is empty. |
| 1194 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1195 | const char *Exec = |
Daniel Dunbar | 8cac5f7 | 2009-03-20 16:06:39 +0000 | [diff] [blame] | 1196 | Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str()); |
| 1197 | Dest.addCommand(new Command(Exec, CmdArgs)); |
| 1198 | } |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1199 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1200 | static const char *MakeFormattedString(const ArgList &Args, |
| 1201 | const llvm::format_object_base &Fmt) { |
| 1202 | std::string Str; |
| 1203 | llvm::raw_string_ostream(Str) << Fmt; |
| 1204 | return Args.MakeArgString(Str.c_str()); |
| 1205 | } |
| 1206 | |
| 1207 | /// Helper routine for seeing if we should use dsymutil; this is a |
| 1208 | /// gcc compatible hack, we should remove it and use the input |
| 1209 | /// type information. |
| 1210 | static bool isSourceSuffix(const char *Str) { |
| 1211 | // match: 'C', 'CPP', 'c', 'cc', 'cp', 'c++', 'cpp', 'cxx', 'm', |
| 1212 | // 'mm'. |
| 1213 | switch (strlen(Str)) { |
| 1214 | default: |
| 1215 | return false; |
| 1216 | case 1: |
| 1217 | return (memcmp(Str, "C", 1) == 0 || |
| 1218 | memcmp(Str, "c", 1) == 0 || |
| 1219 | memcmp(Str, "m", 1) == 0); |
| 1220 | case 2: |
| 1221 | return (memcmp(Str, "cc", 2) == 0 || |
| 1222 | memcmp(Str, "cp", 2) == 0 || |
| 1223 | memcmp(Str, "mm", 2) == 0); |
| 1224 | case 3: |
| 1225 | return (memcmp(Str, "CPP", 3) == 0 || |
| 1226 | memcmp(Str, "c++", 3) == 0 || |
| 1227 | memcmp(Str, "cpp", 3) == 0 || |
| 1228 | memcmp(Str, "cxx", 3) == 0); |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) { |
| 1233 | for (unsigned i=0; i < 3; ++i) { |
| 1234 | if (A[i] > B[i]) return false; |
| 1235 | if (A[i] < B[i]) return true; |
| 1236 | } |
| 1237 | return false; |
| 1238 | } |
| 1239 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1240 | static bool isMacosxVersionLT(unsigned (&A)[3], |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1241 | unsigned V0, unsigned V1=0, unsigned V2=0) { |
| 1242 | unsigned B[3] = { V0, V1, V2 }; |
| 1243 | return isMacosxVersionLT(A, B); |
| 1244 | } |
| 1245 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1246 | const toolchains::Darwin_X86 &darwin::Link::getDarwinToolChain() const { |
| 1247 | return reinterpret_cast<const toolchains::Darwin_X86&>(getToolChain()); |
| 1248 | } |
| 1249 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1250 | void darwin::Link::AddDarwinArch(const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1251 | ArgStringList &CmdArgs) const { |
| 1252 | // Derived from darwin_arch spec. |
| 1253 | CmdArgs.push_back("-arch"); |
| 1254 | CmdArgs.push_back(getToolChain().getArchName().c_str()); |
| 1255 | } |
| 1256 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1257 | void darwin::Link::AddDarwinSubArch(const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1258 | ArgStringList &CmdArgs) const { |
| 1259 | // Derived from darwin_subarch spec, not sure what the distinction |
| 1260 | // exists for but at least for this chain it is the same. |
| 1261 | AddDarwinArch(Args, CmdArgs); |
| 1262 | } |
| 1263 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1264 | void darwin::Link::AddLinkArgs(const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1265 | ArgStringList &CmdArgs) const { |
| 1266 | const Driver &D = getToolChain().getHost().getDriver(); |
| 1267 | |
| 1268 | // Derived from the "link" spec. |
| 1269 | Args.AddAllArgs(CmdArgs, options::OPT_static); |
| 1270 | if (!Args.hasArg(options::OPT_static)) |
| 1271 | CmdArgs.push_back("-dynamic"); |
| 1272 | if (Args.hasArg(options::OPT_fgnu_runtime)) { |
| 1273 | // FIXME: gcc replaces -lobjc in forward args with -lobjc-gnu |
| 1274 | // here. How do we wish to handle such things? |
| 1275 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1276 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1277 | if (!Args.hasArg(options::OPT_dynamiclib)) { |
| 1278 | if (Args.hasArg(options::OPT_force__cpusubtype__ALL)) { |
| 1279 | AddDarwinArch(Args, CmdArgs); |
| 1280 | CmdArgs.push_back("-force_cpusubtype_ALL"); |
| 1281 | } else |
| 1282 | AddDarwinSubArch(Args, CmdArgs); |
| 1283 | |
| 1284 | Args.AddLastArg(CmdArgs, options::OPT_bundle); |
| 1285 | Args.AddAllArgs(CmdArgs, options::OPT_bundle__loader); |
| 1286 | Args.AddAllArgs(CmdArgs, options::OPT_client__name); |
| 1287 | |
| 1288 | Arg *A; |
| 1289 | if ((A = Args.getLastArg(options::OPT_compatibility__version)) || |
| 1290 | (A = Args.getLastArg(options::OPT_current__version)) || |
| 1291 | (A = Args.getLastArg(options::OPT_install__name))) |
| 1292 | D.Diag(clang::diag::err_drv_argument_only_allowed_with) |
| 1293 | << A->getAsString(Args) << "-dynamiclib"; |
| 1294 | |
| 1295 | Args.AddLastArg(CmdArgs, options::OPT_force__flat__namespace); |
| 1296 | Args.AddLastArg(CmdArgs, options::OPT_keep__private__externs); |
| 1297 | Args.AddLastArg(CmdArgs, options::OPT_private__bundle); |
| 1298 | } else { |
| 1299 | CmdArgs.push_back("-dylib"); |
| 1300 | |
| 1301 | Arg *A; |
| 1302 | if ((A = Args.getLastArg(options::OPT_bundle)) || |
| 1303 | (A = Args.getLastArg(options::OPT_bundle__loader)) || |
| 1304 | (A = Args.getLastArg(options::OPT_client__name)) || |
| 1305 | (A = Args.getLastArg(options::OPT_force__flat__namespace)) || |
| 1306 | (A = Args.getLastArg(options::OPT_keep__private__externs)) || |
| 1307 | (A = Args.getLastArg(options::OPT_private__bundle))) |
| 1308 | D.Diag(clang::diag::err_drv_argument_not_allowed_with) |
| 1309 | << A->getAsString(Args) << "-dynamiclib"; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1310 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1311 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_compatibility__version, |
| 1312 | "-dylib_compatibility_version"); |
| 1313 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_current__version, |
| 1314 | "-dylib_current_version"); |
| 1315 | |
| 1316 | if (Args.hasArg(options::OPT_force__cpusubtype__ALL)) { |
| 1317 | AddDarwinArch(Args, CmdArgs); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1318 | // NOTE: We don't add -force_cpusubtype_ALL on this path. Ok. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1319 | } else |
| 1320 | AddDarwinSubArch(Args, CmdArgs); |
| 1321 | |
| 1322 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_install__name, |
| 1323 | "-dylib_install_name"); |
| 1324 | } |
| 1325 | |
| 1326 | Args.AddLastArg(CmdArgs, options::OPT_all__load); |
| 1327 | Args.AddAllArgs(CmdArgs, options::OPT_allowable__client); |
| 1328 | Args.AddLastArg(CmdArgs, options::OPT_bind__at__load); |
| 1329 | Args.AddLastArg(CmdArgs, options::OPT_dead__strip); |
| 1330 | Args.AddLastArg(CmdArgs, options::OPT_no__dead__strip__inits__and__terms); |
| 1331 | Args.AddAllArgs(CmdArgs, options::OPT_dylib__file); |
| 1332 | Args.AddLastArg(CmdArgs, options::OPT_dynamic); |
| 1333 | Args.AddAllArgs(CmdArgs, options::OPT_exported__symbols__list); |
| 1334 | Args.AddLastArg(CmdArgs, options::OPT_flat__namespace); |
| 1335 | Args.AddAllArgs(CmdArgs, options::OPT_headerpad__max__install__names); |
| 1336 | Args.AddAllArgs(CmdArgs, options::OPT_image__base); |
| 1337 | Args.AddAllArgs(CmdArgs, options::OPT_init); |
| 1338 | |
| 1339 | if (!Args.hasArg(options::OPT_mmacosx_version_min_EQ)) { |
| 1340 | if (!Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1341 | // FIXME: I don't understand what is going on here. This is |
| 1342 | // supposed to come from darwin_ld_minversion, but gcc doesn't |
| 1343 | // seem to be following that; it must be getting overridden |
| 1344 | // somewhere. |
| 1345 | CmdArgs.push_back("-macosx_version_min"); |
| 1346 | CmdArgs.push_back(getDarwinToolChain().getMacosxVersionStr()); |
| 1347 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1348 | } else { |
| 1349 | // Adding all arguments doesn't make sense here but this is what |
| 1350 | // gcc does. |
| 1351 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_mmacosx_version_min_EQ, |
| 1352 | "-macosx_version_min"); |
| 1353 | } |
| 1354 | |
| 1355 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_miphoneos_version_min_EQ, |
| 1356 | "-iphoneos_version_min"); |
| 1357 | Args.AddLastArg(CmdArgs, options::OPT_nomultidefs); |
| 1358 | Args.AddLastArg(CmdArgs, options::OPT_multi__module); |
| 1359 | Args.AddLastArg(CmdArgs, options::OPT_single__module); |
| 1360 | Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined); |
| 1361 | Args.AddAllArgs(CmdArgs, options::OPT_multiply__defined__unused); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1362 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1363 | if (Args.hasArg(options::OPT_fpie)) |
| 1364 | CmdArgs.push_back("-pie"); |
| 1365 | |
| 1366 | Args.AddLastArg(CmdArgs, options::OPT_prebind); |
| 1367 | Args.AddLastArg(CmdArgs, options::OPT_noprebind); |
| 1368 | Args.AddLastArg(CmdArgs, options::OPT_nofixprebinding); |
| 1369 | Args.AddLastArg(CmdArgs, options::OPT_prebind__all__twolevel__modules); |
| 1370 | Args.AddLastArg(CmdArgs, options::OPT_read__only__relocs); |
| 1371 | Args.AddAllArgs(CmdArgs, options::OPT_sectcreate); |
| 1372 | Args.AddAllArgs(CmdArgs, options::OPT_sectorder); |
| 1373 | Args.AddAllArgs(CmdArgs, options::OPT_seg1addr); |
| 1374 | Args.AddAllArgs(CmdArgs, options::OPT_segprot); |
| 1375 | Args.AddAllArgs(CmdArgs, options::OPT_segaddr); |
| 1376 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__only__addr); |
| 1377 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__write__addr); |
| 1378 | Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table); |
| 1379 | Args.AddAllArgs(CmdArgs, options::OPT_seg__addr__table__filename); |
| 1380 | Args.AddAllArgs(CmdArgs, options::OPT_sub__library); |
| 1381 | Args.AddAllArgs(CmdArgs, options::OPT_sub__umbrella); |
| 1382 | Args.AddAllArgsTranslated(CmdArgs, options::OPT_isysroot, "-syslibroot"); |
| 1383 | Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace); |
| 1384 | Args.AddLastArg(CmdArgs, options::OPT_twolevel__namespace__hints); |
| 1385 | Args.AddAllArgs(CmdArgs, options::OPT_umbrella); |
| 1386 | Args.AddAllArgs(CmdArgs, options::OPT_undefined); |
| 1387 | Args.AddAllArgs(CmdArgs, options::OPT_unexported__symbols__list); |
| 1388 | Args.AddAllArgs(CmdArgs, options::OPT_weak__reference__mismatches); |
| 1389 | |
| 1390 | if (!Args.hasArg(options::OPT_weak__reference__mismatches)) { |
| 1391 | CmdArgs.push_back("-weak_reference_mismatches"); |
| 1392 | CmdArgs.push_back("non-weak"); |
| 1393 | } |
| 1394 | |
| 1395 | Args.AddLastArg(CmdArgs, options::OPT_X_Flag); |
| 1396 | Args.AddAllArgs(CmdArgs, options::OPT_y); |
| 1397 | Args.AddLastArg(CmdArgs, options::OPT_w); |
| 1398 | Args.AddAllArgs(CmdArgs, options::OPT_pagezero__size); |
| 1399 | Args.AddAllArgs(CmdArgs, options::OPT_segs__read__); |
| 1400 | Args.AddLastArg(CmdArgs, options::OPT_seglinkedit); |
| 1401 | Args.AddLastArg(CmdArgs, options::OPT_noseglinkedit); |
| 1402 | Args.AddAllArgs(CmdArgs, options::OPT_sectalign); |
| 1403 | Args.AddAllArgs(CmdArgs, options::OPT_sectobjectsymbols); |
| 1404 | Args.AddAllArgs(CmdArgs, options::OPT_segcreate); |
| 1405 | Args.AddLastArg(CmdArgs, options::OPT_whyload); |
| 1406 | Args.AddLastArg(CmdArgs, options::OPT_whatsloaded); |
| 1407 | Args.AddAllArgs(CmdArgs, options::OPT_dylinker__install__name); |
| 1408 | Args.AddLastArg(CmdArgs, options::OPT_dylinker); |
| 1409 | Args.AddLastArg(CmdArgs, options::OPT_Mach); |
| 1410 | } |
| 1411 | |
| 1412 | void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1413 | Job &Dest, const InputInfo &Output, |
| 1414 | const InputInfoList &Inputs, |
| 1415 | const ArgList &Args, |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1416 | const char *LinkingOutput) const { |
| 1417 | assert(Output.getType() == types::TY_Image && "Invalid linker output type."); |
| 1418 | // The logic here is derived from gcc's behavior; most of which |
| 1419 | // comes from specs (starting with link_command). Consult gcc for |
| 1420 | // more information. |
| 1421 | |
| 1422 | // FIXME: The spec references -fdump= which seems to have |
| 1423 | // disappeared? |
| 1424 | |
| 1425 | ArgStringList CmdArgs; |
| 1426 | |
| 1427 | // I'm not sure why this particular decomposition exists in gcc, but |
| 1428 | // we follow suite for ease of comparison. |
| 1429 | AddLinkArgs(Args, CmdArgs); |
| 1430 | |
| 1431 | // FIXME: gcc has %{x} in here. How could this ever happen? Cruft? |
| 1432 | Args.AddAllArgs(CmdArgs, options::OPT_d_Flag); |
| 1433 | Args.AddAllArgs(CmdArgs, options::OPT_s); |
| 1434 | Args.AddAllArgs(CmdArgs, options::OPT_t); |
| 1435 | Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag); |
| 1436 | Args.AddAllArgs(CmdArgs, options::OPT_u_Group); |
| 1437 | Args.AddAllArgs(CmdArgs, options::OPT_A); |
| 1438 | Args.AddLastArg(CmdArgs, options::OPT_e); |
| 1439 | Args.AddAllArgs(CmdArgs, options::OPT_m_Separate); |
| 1440 | Args.AddAllArgs(CmdArgs, options::OPT_r); |
| 1441 | |
| 1442 | // FIXME: This is just being pedantically bug compatible, gcc |
| 1443 | // doesn't *mean* to forward this, it just does (yay for pattern |
| 1444 | // matching). It doesn't work, of course. |
| 1445 | Args.AddAllArgs(CmdArgs, options::OPT_object); |
| 1446 | |
| 1447 | CmdArgs.push_back("-o"); |
| 1448 | CmdArgs.push_back(Output.getFilename()); |
| 1449 | |
| 1450 | unsigned MacosxVersion[3]; |
| 1451 | if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) { |
| 1452 | bool HadExtra; |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1453 | if (!Driver::GetReleaseVersion(A->getValue(Args), MacosxVersion[0], |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1454 | MacosxVersion[1], MacosxVersion[2], |
| 1455 | HadExtra) || |
| 1456 | HadExtra) { |
| 1457 | const Driver &D = getToolChain().getHost().getDriver(); |
| 1458 | D.Diag(clang::diag::err_drv_invalid_version_number) |
| 1459 | << A->getAsString(Args); |
| 1460 | } |
| 1461 | } else { |
| 1462 | getDarwinToolChain().getMacosxVersion(MacosxVersion); |
| 1463 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1464 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1465 | if (!Args.hasArg(options::OPT_A) && |
| 1466 | !Args.hasArg(options::OPT_nostdlib) && |
| 1467 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 1468 | // Derived from startfile spec. |
| 1469 | if (Args.hasArg(options::OPT_dynamiclib)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1470 | // Derived from darwin_dylib1 spec. |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1471 | if (isMacosxVersionLT(MacosxVersion, 10, 5)) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1472 | CmdArgs.push_back("-ldylib1.o"); |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1473 | else if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1474 | CmdArgs.push_back("-ldylib1.10.5.o"); |
| 1475 | } else { |
| 1476 | if (Args.hasArg(options::OPT_bundle)) { |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1477 | if (!Args.hasArg(options::OPT_static)) { |
| 1478 | // Derived from darwin_bundle1 spec. |
| 1479 | if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
| 1480 | CmdArgs.push_back("-lbundle1.o"); |
| 1481 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1482 | } else { |
| 1483 | if (Args.hasArg(options::OPT_pg)) { |
| 1484 | if (Args.hasArg(options::OPT_static) || |
| 1485 | Args.hasArg(options::OPT_object) || |
| 1486 | Args.hasArg(options::OPT_preload)) { |
| 1487 | CmdArgs.push_back("-lgcrt0.o"); |
| 1488 | } else { |
| 1489 | CmdArgs.push_back("-lgcrt1.o"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1490 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1491 | // darwin_crt2 spec is empty. |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1492 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1493 | } else { |
| 1494 | if (Args.hasArg(options::OPT_static) || |
| 1495 | Args.hasArg(options::OPT_object) || |
| 1496 | Args.hasArg(options::OPT_preload)) { |
| 1497 | CmdArgs.push_back("-lcrt0.o"); |
| 1498 | } else { |
| 1499 | // Derived from darwin_crt1 spec. |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1500 | if (isMacosxVersionLT(MacosxVersion, 10, 5)) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1501 | CmdArgs.push_back("-lcrt1.o"); |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1502 | else if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1503 | CmdArgs.push_back("-lcrt1.10.5.o"); |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1504 | else |
| 1505 | CmdArgs.push_back("-lcrt1.10.6.o"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1506 | |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1507 | // darwin_crt2 spec is empty. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1508 | } |
| 1509 | } |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | if (Args.hasArg(options::OPT_shared_libgcc) && |
| 1514 | !Args.hasArg(options::OPT_miphoneos_version_min_EQ) && |
| 1515 | isMacosxVersionLT(MacosxVersion, 10, 5)) { |
| 1516 | const char *Str = getToolChain().GetFilePath(C, "crt3.o").c_str(); |
| 1517 | CmdArgs.push_back(Args.MakeArgString(Str)); |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1522 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1523 | if (Args.hasArg(options::OPT_fopenmp)) |
| 1524 | // This is more complicated in gcc... |
| 1525 | CmdArgs.push_back("-lgomp"); |
| 1526 | |
| 1527 | // FIXME: Derive these correctly. |
| 1528 | const char *TCDir = getDarwinToolChain().getToolChainDir().c_str(); |
| 1529 | if (getToolChain().getArchName() == "x86_64") { |
| 1530 | CmdArgs.push_back(MakeFormattedString(Args, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1531 | llvm::format("-L/usr/lib/gcc/%s/x86_64", TCDir))); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1532 | // Intentionally duplicated for (temporary) gcc bug compatibility. |
| 1533 | CmdArgs.push_back(MakeFormattedString(Args, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1534 | llvm::format("-L/usr/lib/gcc/%s/x86_64", TCDir))); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1535 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1536 | CmdArgs.push_back(MakeFormattedString(Args, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1537 | llvm::format("-L/usr/lib/%s", TCDir))); |
| 1538 | CmdArgs.push_back(MakeFormattedString(Args, |
| 1539 | llvm::format("-L/usr/lib/gcc/%s", TCDir))); |
| 1540 | // Intentionally duplicated for (temporary) gcc bug compatibility. |
| 1541 | CmdArgs.push_back(MakeFormattedString(Args, |
| 1542 | llvm::format("-L/usr/lib/gcc/%s", TCDir))); |
| 1543 | CmdArgs.push_back(MakeFormattedString(Args, |
| 1544 | llvm::format("-L/usr/lib/gcc/%s/../../../%s", TCDir, TCDir))); |
| 1545 | CmdArgs.push_back(MakeFormattedString(Args, |
| 1546 | llvm::format("-L/usr/lib/gcc/%s/../../..", TCDir))); |
| 1547 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1548 | for (InputInfoList::const_iterator |
| 1549 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1550 | const InputInfo &II = *it; |
| 1551 | if (II.isFilename()) |
| 1552 | CmdArgs.push_back(II.getFilename()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1553 | else |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1554 | II.getInputArg().renderAsInput(Args, CmdArgs); |
| 1555 | } |
| 1556 | |
| 1557 | if (LinkingOutput) { |
| 1558 | CmdArgs.push_back("-arch_multiple"); |
| 1559 | CmdArgs.push_back("-final_output"); |
| 1560 | CmdArgs.push_back(LinkingOutput); |
| 1561 | } |
| 1562 | |
| 1563 | if (Args.hasArg(options::OPT_fprofile_arcs) || |
| 1564 | Args.hasArg(options::OPT_fprofile_generate) || |
| 1565 | Args.hasArg(options::OPT_fcreate_profile) || |
| 1566 | Args.hasArg(options::OPT_coverage)) |
| 1567 | CmdArgs.push_back("-lgcov"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1568 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1569 | if (Args.hasArg(options::OPT_fnested_functions)) |
| 1570 | CmdArgs.push_back("-allow_stack_execute"); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1571 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1572 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 1573 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
Daniel Dunbar | edfa02b | 2009-04-08 06:06:21 +0000 | [diff] [blame] | 1574 | // FIXME: g++ is more complicated here, it tries to put -lstdc++ |
| 1575 | // before -lm, for example. |
| 1576 | if (getToolChain().getHost().getDriver().CCCIsCXX) |
| 1577 | CmdArgs.push_back("-lstdc++"); |
| 1578 | |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1579 | // link_ssp spec is empty. |
| 1580 | |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1581 | // Derived from libgcc and lib specs but refactored. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1582 | if (Args.hasArg(options::OPT_static)) { |
| 1583 | CmdArgs.push_back("-lgcc_static"); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1584 | } else { |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1585 | if (Args.hasArg(options::OPT_static_libgcc)) { |
| 1586 | CmdArgs.push_back("-lgcc_eh"); |
| 1587 | } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { |
| 1588 | // Derived from darwin_iphoneos_libgcc spec. |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1589 | CmdArgs.push_back("-lgcc_s.10.5"); |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1590 | } else if (Args.hasArg(options::OPT_shared_libgcc) || |
| 1591 | Args.hasArg(options::OPT_fexceptions) || |
| 1592 | Args.hasArg(options::OPT_fgnu_runtime)) { |
| 1593 | // FIXME: This is probably broken on 10.3? |
| 1594 | if (isMacosxVersionLT(MacosxVersion, 10, 5)) |
| 1595 | CmdArgs.push_back("-lgcc_s.10.4"); |
| 1596 | else if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
| 1597 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 1598 | } else { |
| 1599 | if (isMacosxVersionLT(MacosxVersion, 10, 3, 9)) |
| 1600 | ; // Do nothing. |
| 1601 | else if (isMacosxVersionLT(MacosxVersion, 10, 5)) |
| 1602 | CmdArgs.push_back("-lgcc_s.10.4"); |
| 1603 | else if (isMacosxVersionLT(MacosxVersion, 10, 6)) |
| 1604 | CmdArgs.push_back("-lgcc_s.10.5"); |
| 1605 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1606 | |
Daniel Dunbar | 8a8d8af | 2009-04-01 03:17:40 +0000 | [diff] [blame] | 1607 | if (isMacosxVersionLT(MacosxVersion, 10, 6)) { |
| 1608 | CmdArgs.push_back("-lgcc"); |
| 1609 | CmdArgs.push_back("-lSystem"); |
| 1610 | } else { |
| 1611 | CmdArgs.push_back("-lSystem"); |
| 1612 | CmdArgs.push_back("-lgcc"); |
| 1613 | } |
| 1614 | } |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | if (!Args.hasArg(options::OPT_A) && |
| 1618 | !Args.hasArg(options::OPT_nostdlib) && |
| 1619 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 1620 | // endfile_spec is empty. |
| 1621 | } |
| 1622 | |
| 1623 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 1624 | Args.AddAllArgs(CmdArgs, options::OPT_F); |
| 1625 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1626 | const char *Exec = |
Daniel Dunbar | 9961293 | 2009-04-23 23:17:23 +0000 | [diff] [blame] | 1627 | Args.MakeArgString(getToolChain().GetProgramPath(C, "ld").c_str()); |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1628 | Dest.addCommand(new Command(Exec, CmdArgs)); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1629 | |
Daniel Dunbar | 0b46e1b | 2009-04-04 00:55:30 +0000 | [diff] [blame] | 1630 | // Find the first non-empty base input (we want to ignore linker |
| 1631 | // inputs). |
| 1632 | const char *BaseInput = ""; |
| 1633 | for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { |
| 1634 | if (Inputs[i].getBaseInput()[0] != '\0') { |
| 1635 | BaseInput = Inputs[i].getBaseInput(); |
| 1636 | break; |
| 1637 | } |
| 1638 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1639 | |
Daniel Dunbar | 3ed2945 | 2009-04-24 03:03:52 +0000 | [diff] [blame] | 1640 | // Run dsymutil if we are making an executable in a single step. |
| 1641 | // |
| 1642 | // FIXME: Currently we don't want to do this when we are part of a |
| 1643 | // universal build step, as this would end up creating stray temp |
| 1644 | // files. |
| 1645 | if (!LinkingOutput && |
| 1646 | Args.getLastArg(options::OPT_g_Group) && |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1647 | !Args.getLastArg(options::OPT_gstabs) && |
| 1648 | !Args.getLastArg(options::OPT_g0)) { |
| 1649 | // FIXME: This is gross, but matches gcc. The test only considers |
| 1650 | // the suffix (not the -x type), and then only of the first |
Daniel Dunbar | 0b46e1b | 2009-04-04 00:55:30 +0000 | [diff] [blame] | 1651 | // source input. Awesome. |
| 1652 | const char *Suffix = strrchr(BaseInput, '.'); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1653 | if (Suffix && isSourceSuffix(Suffix + 1)) { |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1654 | const char *Exec = |
| 1655 | Args.MakeArgString(getToolChain().GetProgramPath(C, "dsymutil").c_str()); |
Daniel Dunbar | 02633b5 | 2009-03-26 16:23:12 +0000 | [diff] [blame] | 1656 | ArgStringList CmdArgs; |
| 1657 | CmdArgs.push_back(Output.getFilename()); |
| 1658 | C.getJobs().addCommand(new Command(Exec, CmdArgs)); |
| 1659 | } |
| 1660 | } |
| 1661 | } |
| 1662 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1663 | void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1664 | Job &Dest, const InputInfo &Output, |
| 1665 | const InputInfoList &Inputs, |
| 1666 | const ArgList &Args, |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1667 | const char *LinkingOutput) const { |
| 1668 | ArgStringList CmdArgs; |
| 1669 | |
| 1670 | CmdArgs.push_back("-create"); |
| 1671 | assert(Output.isFilename() && "Unexpected lipo output."); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 1672 | |
| 1673 | CmdArgs.push_back("-output"); |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1674 | CmdArgs.push_back(Output.getFilename()); |
Daniel Dunbar | a428df8 | 2009-03-24 00:24:37 +0000 | [diff] [blame] | 1675 | |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1676 | for (InputInfoList::const_iterator |
| 1677 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1678 | const InputInfo &II = *it; |
| 1679 | assert(II.isFilename() && "Unexpected lipo input."); |
| 1680 | CmdArgs.push_back(II.getFilename()); |
| 1681 | } |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1682 | const char *Exec = |
Daniel Dunbar | ff7488d | 2009-03-20 00:52:38 +0000 | [diff] [blame] | 1683 | Args.MakeArgString(getToolChain().GetProgramPath(C, "lipo").c_str()); |
| 1684 | Dest.addCommand(new Command(Exec, CmdArgs)); |
| 1685 | } |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1686 | |
Ed Schouten | c66a5a3 | 2009-04-02 19:13:12 +0000 | [diff] [blame] | 1687 | |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1688 | void freebsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1689 | Job &Dest, const InputInfo &Output, |
| 1690 | const InputInfoList &Inputs, |
| 1691 | const ArgList &Args, |
| 1692 | const char *LinkingOutput) const |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1693 | { |
| 1694 | ArgStringList CmdArgs; |
| 1695 | |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1696 | // When building 32-bit code on FreeBSD/amd64, we have to explicitly |
| 1697 | // instruct as in the base system to assemble 32-bit code. |
| 1698 | if (getToolChain().getArchName() == "i386") |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1699 | CmdArgs.push_back("--32"); |
| 1700 | |
| 1701 | Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, |
| 1702 | options::OPT_Xassembler); |
| 1703 | |
| 1704 | CmdArgs.push_back("-o"); |
| 1705 | if (Output.isPipe()) |
| 1706 | CmdArgs.push_back("-"); |
| 1707 | else |
| 1708 | CmdArgs.push_back(Output.getFilename()); |
| 1709 | |
| 1710 | for (InputInfoList::const_iterator |
| 1711 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
| 1712 | const InputInfo &II = *it; |
| 1713 | if (II.isPipe()) |
| 1714 | CmdArgs.push_back("-"); |
| 1715 | else |
| 1716 | CmdArgs.push_back(II.getFilename()); |
| 1717 | } |
| 1718 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1719 | const char *Exec = |
Daniel Dunbar | 68a31d4 | 2009-03-31 17:45:15 +0000 | [diff] [blame] | 1720 | Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str()); |
| 1721 | Dest.addCommand(new Command(Exec, CmdArgs)); |
| 1722 | } |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1723 | |
| 1724 | void freebsd::Link::ConstructJob(Compilation &C, const JobAction &JA, |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1725 | Job &Dest, const InputInfo &Output, |
| 1726 | const InputInfoList &Inputs, |
| 1727 | const ArgList &Args, |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1728 | const char *LinkingOutput) const |
| 1729 | { |
| 1730 | ArgStringList CmdArgs; |
| 1731 | |
| 1732 | if (Args.hasArg(options::OPT_static)) { |
| 1733 | CmdArgs.push_back("-Bstatic"); |
| 1734 | } else { |
| 1735 | CmdArgs.push_back("--eh-frame-hdr"); |
| 1736 | if (Args.hasArg(options::OPT_shared)) { |
| 1737 | CmdArgs.push_back("-Bshareable"); |
| 1738 | } else { |
| 1739 | CmdArgs.push_back("-dynamic-linker"); |
| 1740 | CmdArgs.push_back("/libexec/ld-elf.so.1"); |
| 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | // When building 32-bit code on FreeBSD/amd64, we have to explicitly |
| 1745 | // instruct ld in the base system to link 32-bit code. |
| 1746 | if (getToolChain().getArchName() == "i386") { |
| 1747 | CmdArgs.push_back("-m"); |
| 1748 | CmdArgs.push_back("elf_i386_fbsd"); |
| 1749 | } |
| 1750 | |
| 1751 | if (Output.isPipe()) { |
| 1752 | CmdArgs.push_back("-o"); |
| 1753 | CmdArgs.push_back("-"); |
| 1754 | } else if (Output.isFilename()) { |
| 1755 | CmdArgs.push_back("-o"); |
| 1756 | CmdArgs.push_back(Output.getFilename()); |
| 1757 | } else { |
| 1758 | assert(Output.isNothing() && "Invalid output."); |
| 1759 | } |
| 1760 | |
| 1761 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 1762 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 1763 | if (!Args.hasArg(options::OPT_shared)) { |
| 1764 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crt1.o").c_str())); |
| 1765 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crti.o").c_str())); |
| 1766 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbegin.o").c_str())); |
| 1767 | } else { |
| 1768 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crti.o").c_str())); |
| 1769 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbeginS.o").c_str())); |
| 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | Args.AddAllArgs(CmdArgs, options::OPT_L); |
| 1774 | Args.AddAllArgs(CmdArgs, options::OPT_T_Group); |
| 1775 | Args.AddAllArgs(CmdArgs, options::OPT_e); |
| 1776 | |
| 1777 | for (InputInfoList::const_iterator |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1778 | it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) { |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1779 | const InputInfo &II = *it; |
| 1780 | if (II.isPipe()) |
| 1781 | CmdArgs.push_back("-"); |
| 1782 | else if (II.isFilename()) |
| 1783 | CmdArgs.push_back(II.getFilename()); |
| 1784 | else |
| 1785 | II.getInputArg().renderAsInput(Args, CmdArgs); |
| 1786 | } |
| 1787 | |
| 1788 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 1789 | !Args.hasArg(options::OPT_nodefaultlibs)) { |
| 1790 | // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding |
| 1791 | // the default system libraries. Just mimic this for now. |
| 1792 | CmdArgs.push_back("-lgcc"); |
| 1793 | if (Args.hasArg(options::OPT_static)) { |
| 1794 | CmdArgs.push_back("-lgcc_eh"); |
| 1795 | } else { |
| 1796 | CmdArgs.push_back("--as-needed"); |
| 1797 | CmdArgs.push_back("-lgcc_s"); |
| 1798 | CmdArgs.push_back("--no-as-needed"); |
| 1799 | } |
| 1800 | |
| 1801 | if (Args.hasArg(options::OPT_pthread)) |
| 1802 | CmdArgs.push_back("-lpthread"); |
| 1803 | CmdArgs.push_back("-lc"); |
| 1804 | |
| 1805 | CmdArgs.push_back("-lgcc"); |
| 1806 | if (Args.hasArg(options::OPT_static)) { |
| 1807 | CmdArgs.push_back("-lgcc_eh"); |
| 1808 | } else { |
| 1809 | CmdArgs.push_back("--as-needed"); |
| 1810 | CmdArgs.push_back("-lgcc_s"); |
| 1811 | CmdArgs.push_back("--no-as-needed"); |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | if (!Args.hasArg(options::OPT_nostdlib) && |
| 1816 | !Args.hasArg(options::OPT_nostartfiles)) { |
| 1817 | if (!Args.hasArg(options::OPT_shared)) |
| 1818 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtend.o").c_str())); |
| 1819 | else |
| 1820 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtendS.o").c_str())); |
| 1821 | CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtn.o").c_str())); |
| 1822 | } |
| 1823 | |
Daniel Dunbar | c21c485 | 2009-04-08 23:54:23 +0000 | [diff] [blame] | 1824 | const char *Exec = |
Daniel Dunbar | 008f54a | 2009-04-01 19:36:32 +0000 | [diff] [blame] | 1825 | Args.MakeArgString(getToolChain().GetProgramPath(C, "ld").c_str()); |
| 1826 | Dest.addCommand(new Command(Exec, CmdArgs)); |
| 1827 | } |