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