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