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