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