ToolChains.cpp revision 7433fedce98a58341d0f30c2e12e8d53f3bba575
1//===--- ToolChains.cpp - ToolChain 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 "ToolChains.h" 11 12#include "clang/Driver/Arg.h" 13#include "clang/Driver/ArgList.h" 14#include "clang/Driver/Compilation.h" 15#include "clang/Driver/Driver.h" 16#include "clang/Driver/DriverDiagnostic.h" 17#include "clang/Driver/HostInfo.h" 18#include "clang/Driver/OptTable.h" 19#include "clang/Driver/Option.h" 20#include "clang/Driver/Options.h" 21#include "clang/Basic/Version.h" 22 23#include "llvm/ADT/SmallString.h" 24#include "llvm/ADT/StringExtras.h" 25#include "llvm/Support/ErrorHandling.h" 26#include "llvm/Support/raw_ostream.h" 27#include "llvm/System/Path.h" 28 29#include <cstdlib> // ::getenv 30 31using namespace clang::driver; 32using namespace clang::driver::toolchains; 33 34/// Darwin - Darwin tool chain for i386 and x86_64. 35 36Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple) 37 : ToolChain(Host, Triple), TargetInitialized(false) 38{ 39 // Compute the initial Darwin version based on the host. 40 bool HadExtra; 41 std::string OSName = Triple.getOSName(); 42 if (!Driver::GetReleaseVersion(&OSName[6], 43 DarwinVersion[0], DarwinVersion[1], 44 DarwinVersion[2], HadExtra)) 45 getDriver().Diag(clang::diag::err_drv_invalid_darwin_version) << OSName; 46 47 llvm::raw_string_ostream(MacosxVersionMin) 48 << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.' 49 << DarwinVersion[1]; 50} 51 52types::ID Darwin::LookupTypeForExtension(const char *Ext) const { 53 types::ID Ty = types::lookupTypeForExtension(Ext); 54 55 // Darwin always preprocesses assembly files (unless -x is used explicitly). 56 if (Ty == types::TY_PP_Asm) 57 return types::TY_Asm; 58 59 return Ty; 60} 61 62bool Darwin::HasNativeLLVMSupport() const { 63 return true; 64} 65 66// FIXME: Can we tablegen this? 67static const char *GetArmArchForMArch(llvm::StringRef Value) { 68 if (Value == "armv6k") 69 return "armv6"; 70 71 if (Value == "armv5tej") 72 return "armv5"; 73 74 if (Value == "xscale") 75 return "xscale"; 76 77 if (Value == "armv4t") 78 return "armv4t"; 79 80 if (Value == "armv7" || Value == "armv7-a" || Value == "armv7-r" || 81 Value == "armv7-m" || Value == "armv7a" || Value == "armv7r" || 82 Value == "armv7m") 83 return "armv7"; 84 85 return 0; 86} 87 88// FIXME: Can we tablegen this? 89static const char *GetArmArchForMCpu(llvm::StringRef Value) { 90 if (Value == "arm10tdmi" || Value == "arm1020t" || Value == "arm9e" || 91 Value == "arm946e-s" || Value == "arm966e-s" || 92 Value == "arm968e-s" || Value == "arm10e" || 93 Value == "arm1020e" || Value == "arm1022e" || Value == "arm926ej-s" || 94 Value == "arm1026ej-s") 95 return "armv5"; 96 97 if (Value == "xscale") 98 return "xscale"; 99 100 if (Value == "arm1136j-s" || Value == "arm1136jf-s" || 101 Value == "arm1176jz-s" || Value == "arm1176jzf-s") 102 return "armv6"; 103 104 if (Value == "cortex-a8" || Value == "cortex-r4" || Value == "cortex-m3") 105 return "armv7"; 106 107 return 0; 108} 109 110llvm::StringRef Darwin::getDarwinArchName(const ArgList &Args) const { 111 switch (getTriple().getArch()) { 112 default: 113 return getArchName(); 114 115 case llvm::Triple::arm: { 116 if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) 117 if (const char *Arch = GetArmArchForMArch(A->getValue(Args))) 118 return Arch; 119 120 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) 121 if (const char *Arch = GetArmArchForMCpu(A->getValue(Args))) 122 return Arch; 123 124 return "arm"; 125 } 126 } 127} 128 129DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple) 130 : Darwin(Host, Triple) 131{ 132 // We can only work with 4.2.1 currently. 133 GCCVersion[0] = 4; 134 GCCVersion[1] = 2; 135 GCCVersion[2] = 1; 136 137 // Set up the tool chain paths to match gcc. 138 ToolChainDir = "i686-apple-darwin"; 139 ToolChainDir += llvm::utostr(DarwinVersion[0]); 140 ToolChainDir += "/"; 141 ToolChainDir += llvm::utostr(GCCVersion[0]); 142 ToolChainDir += '.'; 143 ToolChainDir += llvm::utostr(GCCVersion[1]); 144 ToolChainDir += '.'; 145 ToolChainDir += llvm::utostr(GCCVersion[2]); 146 147 // Try the next major version if that tool chain dir is invalid. 148 std::string Tmp = "/usr/lib/gcc/" + ToolChainDir; 149 if (!llvm::sys::Path(Tmp).exists()) { 150 std::string Next = "i686-apple-darwin"; 151 Next += llvm::utostr(DarwinVersion[0] + 1); 152 Next += "/"; 153 Next += llvm::utostr(GCCVersion[0]); 154 Next += '.'; 155 Next += llvm::utostr(GCCVersion[1]); 156 Next += '.'; 157 Next += llvm::utostr(GCCVersion[2]); 158 159 // Use that if it exists, otherwise hope the user isn't linking. 160 // 161 // FIXME: Drop dependency on gcc's tool chain. 162 Tmp = "/usr/lib/gcc/" + Next; 163 if (llvm::sys::Path(Tmp).exists()) 164 ToolChainDir = Next; 165 } 166 167 std::string Path; 168 if (getArchName() == "x86_64") { 169 Path = getDriver().Dir; 170 Path += "/../lib/gcc/"; 171 Path += ToolChainDir; 172 Path += "/x86_64"; 173 getFilePaths().push_back(Path); 174 175 Path = "/usr/lib/gcc/"; 176 Path += ToolChainDir; 177 Path += "/x86_64"; 178 getFilePaths().push_back(Path); 179 } 180 181 Path = getDriver().Dir; 182 Path += "/../lib/gcc/"; 183 Path += ToolChainDir; 184 getFilePaths().push_back(Path); 185 186 Path = "/usr/lib/gcc/"; 187 Path += ToolChainDir; 188 getFilePaths().push_back(Path); 189 190 Path = getDriver().Dir; 191 Path += "/../libexec/gcc/"; 192 Path += ToolChainDir; 193 getProgramPaths().push_back(Path); 194 195 Path = "/usr/libexec/gcc/"; 196 Path += ToolChainDir; 197 getProgramPaths().push_back(Path); 198 199 getProgramPaths().push_back(getDriver().getInstalledDir()); 200 if (getDriver().getInstalledDir() != getDriver().Dir) 201 getProgramPaths().push_back(getDriver().Dir); 202} 203 204Darwin::~Darwin() { 205 // Free tool implementations. 206 for (llvm::DenseMap<unsigned, Tool*>::iterator 207 it = Tools.begin(), ie = Tools.end(); it != ie; ++it) 208 delete it->second; 209} 210 211std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args) const { 212 llvm::Triple Triple(ComputeLLVMTriple(Args)); 213 214 // If the target isn't initialized (e.g., an unknown Darwin platform, return 215 // the default triple). 216 if (!isTargetInitialized()) 217 return Triple.getTriple(); 218 219 unsigned Version[3]; 220 getTargetVersion(Version); 221 222 // Mangle the target version into the OS triple component. For historical 223 // reasons that make little sense, the version passed here is the "darwin" 224 // version, which drops the 10 and offsets by 4. See inverse code when 225 // setting the OS version preprocessor define. 226 if (!isTargetIPhoneOS()) { 227 Version[0] = Version[1] + 4; 228 Version[1] = Version[2]; 229 Version[2] = 0; 230 } else { 231 // Use the environment to communicate that we are targetting iPhoneOS. 232 Triple.setEnvironmentName("iphoneos"); 233 } 234 235 llvm::SmallString<16> Str; 236 llvm::raw_svector_ostream(Str) << "darwin" << Version[0] 237 << "." << Version[1] << "." << Version[2]; 238 Triple.setOSName(Str.str()); 239 240 return Triple.getTriple(); 241} 242 243Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const { 244 Action::ActionClass Key; 245 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 246 Key = Action::AnalyzeJobClass; 247 else 248 Key = JA.getKind(); 249 250 // FIXME: This doesn't belong here, but ideally we will support static soon 251 // anyway. 252 bool HasStatic = (C.getArgs().hasArg(options::OPT_mkernel) || 253 C.getArgs().hasArg(options::OPT_static) || 254 C.getArgs().hasArg(options::OPT_fapple_kext)); 255 bool IsIADefault = IsIntegratedAssemblerDefault() && !HasStatic; 256 bool UseIntegratedAs = C.getArgs().hasFlag(options::OPT_integrated_as, 257 options::OPT_no_integrated_as, 258 IsIADefault); 259 260 Tool *&T = Tools[Key]; 261 if (!T) { 262 switch (Key) { 263 case Action::InputClass: 264 case Action::BindArchClass: 265 assert(0 && "Invalid tool kind."); 266 case Action::PreprocessJobClass: 267 T = new tools::darwin::Preprocess(*this); break; 268 case Action::AnalyzeJobClass: 269 T = new tools::Clang(*this); break; 270 case Action::PrecompileJobClass: 271 case Action::CompileJobClass: 272 T = new tools::darwin::Compile(*this); break; 273 case Action::AssembleJobClass: { 274 if (UseIntegratedAs) 275 T = new tools::ClangAs(*this); 276 else 277 T = new tools::darwin::Assemble(*this); 278 break; 279 } 280 case Action::LinkJobClass: 281 T = new tools::darwin::Link(*this); break; 282 case Action::LipoJobClass: 283 T = new tools::darwin::Lipo(*this); break; 284 case Action::DsymutilJobClass: 285 T = new tools::darwin::Dsymutil(*this); break; 286 } 287 } 288 289 return *T; 290} 291 292void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args, 293 ArgStringList &CmdArgs) const { 294 std::string Tmp; 295 296 // FIXME: Derive these correctly. 297 if (getArchName() == "x86_64") { 298 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + 299 "/x86_64")); 300 // Intentionally duplicated for (temporary) gcc bug compatibility. 301 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + 302 "/x86_64")); 303 } 304 305 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir)); 306 307 Tmp = getDriver().Dir + "/../lib/gcc/" + ToolChainDir; 308 if (llvm::sys::Path(Tmp).exists()) 309 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); 310 Tmp = getDriver().Dir + "/../lib/gcc"; 311 if (llvm::sys::Path(Tmp).exists()) 312 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); 313 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); 314 // Intentionally duplicated for (temporary) gcc bug compatibility. 315 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); 316 Tmp = getDriver().Dir + "/../lib/" + ToolChainDir; 317 if (llvm::sys::Path(Tmp).exists()) 318 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); 319 Tmp = getDriver().Dir + "/../lib"; 320 if (llvm::sys::Path(Tmp).exists()) 321 CmdArgs.push_back(Args.MakeArgString("-L" + Tmp)); 322 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + 323 "/../../../" + ToolChainDir)); 324 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + 325 "/../../..")); 326} 327 328void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args, 329 ArgStringList &CmdArgs) const { 330 // Note that this routine is only used for targetting OS X. 331 332 // Derived from libgcc and lib specs but refactored. 333 if (Args.hasArg(options::OPT_static)) { 334 CmdArgs.push_back("-lgcc_static"); 335 } else { 336 if (Args.hasArg(options::OPT_static_libgcc)) { 337 CmdArgs.push_back("-lgcc_eh"); 338 } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { 339 // Derived from darwin_iphoneos_libgcc spec. 340 if (isTargetIPhoneOS()) { 341 CmdArgs.push_back("-lgcc_s.1"); 342 } else { 343 CmdArgs.push_back("-lgcc_s.10.5"); 344 } 345 } else if (Args.hasArg(options::OPT_shared_libgcc) || 346 Args.hasFlag(options::OPT_fexceptions, 347 options::OPT_fno_exceptions) || 348 Args.hasArg(options::OPT_fgnu_runtime)) { 349 // FIXME: This is probably broken on 10.3? 350 if (isMacosxVersionLT(10, 5)) 351 CmdArgs.push_back("-lgcc_s.10.4"); 352 else if (isMacosxVersionLT(10, 6)) 353 CmdArgs.push_back("-lgcc_s.10.5"); 354 } else { 355 if (isMacosxVersionLT(10, 3, 9)) 356 ; // Do nothing. 357 else if (isMacosxVersionLT(10, 5)) 358 CmdArgs.push_back("-lgcc_s.10.4"); 359 else if (isMacosxVersionLT(10, 6)) 360 CmdArgs.push_back("-lgcc_s.10.5"); 361 } 362 363 if (isTargetIPhoneOS() || isMacosxVersionLT(10, 6)) { 364 CmdArgs.push_back("-lgcc"); 365 CmdArgs.push_back("-lSystem"); 366 } else { 367 CmdArgs.push_back("-lSystem"); 368 CmdArgs.push_back("-lgcc"); 369 } 370 } 371} 372 373DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple) 374 : Darwin(Host, Triple) 375{ 376 getProgramPaths().push_back(getDriver().getInstalledDir()); 377 if (getDriver().getInstalledDir() != getDriver().Dir) 378 getProgramPaths().push_back(getDriver().Dir); 379 380 // We expect 'as', 'ld', etc. to be adjacent to our install dir. 381 getProgramPaths().push_back(getDriver().getInstalledDir()); 382 if (getDriver().getInstalledDir() != getDriver().Dir) 383 getProgramPaths().push_back(getDriver().Dir); 384 385 // For fallback, we need to know how to find the GCC cc1 executables, so we 386 // also add the GCC libexec paths. This is legiy code that can be removed once 387 // fallback is no longer useful. 388 std::string ToolChainDir = "i686-apple-darwin"; 389 ToolChainDir += llvm::utostr(DarwinVersion[0]); 390 ToolChainDir += "/4.2.1"; 391 392 std::string Path = getDriver().Dir; 393 Path += "/../libexec/gcc/"; 394 Path += ToolChainDir; 395 getProgramPaths().push_back(Path); 396 397 Path = "/usr/libexec/gcc/"; 398 Path += ToolChainDir; 399 getProgramPaths().push_back(Path); 400} 401 402void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args, 403 ArgStringList &CmdArgs) const { 404 // The Clang toolchain uses explicit paths for internal libraries. 405 406 // Unfortunately, we still might depend on a few of the libraries that are 407 // only available in the gcc library directory (in particular 408 // libstdc++.dylib). For now, hardcode the path to the known install location. 409 llvm::sys::Path P(getDriver().Dir); 410 P.eraseComponent(); // .../usr/bin -> ../usr 411 P.appendComponent("lib"); 412 P.appendComponent("gcc"); 413 switch (getTriple().getArch()) { 414 default: 415 assert(0 && "Invalid Darwin arch!"); 416 case llvm::Triple::x86: 417 case llvm::Triple::x86_64: 418 P.appendComponent("i686-apple-darwin10"); 419 break; 420 case llvm::Triple::arm: 421 case llvm::Triple::thumb: 422 P.appendComponent("arm-apple-darwin10"); 423 break; 424 case llvm::Triple::ppc: 425 case llvm::Triple::ppc64: 426 P.appendComponent("powerpc-apple-darwin10"); 427 break; 428 } 429 P.appendComponent("4.2.1"); 430 431 // Determine the arch specific GCC subdirectory. 432 const char *ArchSpecificDir = 0; 433 switch (getTriple().getArch()) { 434 default: 435 break; 436 case llvm::Triple::arm: 437 case llvm::Triple::thumb: { 438 std::string Triple = ComputeLLVMTriple(Args); 439 llvm::StringRef TripleStr = Triple; 440 if (TripleStr.startswith("armv5") || TripleStr.startswith("thumbv5")) 441 ArchSpecificDir = "v5"; 442 else if (TripleStr.startswith("armv6") || TripleStr.startswith("thumbv6")) 443 ArchSpecificDir = "v6"; 444 else if (TripleStr.startswith("armv7") || TripleStr.startswith("thumbv7")) 445 ArchSpecificDir = "v7"; 446 break; 447 } 448 case llvm::Triple::ppc64: 449 ArchSpecificDir = "ppc64"; 450 break; 451 case llvm::Triple::x86_64: 452 ArchSpecificDir = "x86_64"; 453 break; 454 } 455 456 if (ArchSpecificDir) { 457 P.appendComponent(ArchSpecificDir); 458 if (P.exists()) 459 CmdArgs.push_back(Args.MakeArgString("-L" + P.str())); 460 P.eraseComponent(); 461 } 462 463 if (P.exists()) 464 CmdArgs.push_back(Args.MakeArgString("-L" + P.str())); 465} 466 467void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, 468 ArgStringList &CmdArgs) const { 469 // Darwin doesn't support real static executables, don't link any runtime 470 // libraries with -static. 471 if (Args.hasArg(options::OPT_static)) 472 return; 473 474 // Reject -static-libgcc for now, we can deal with this when and if someone 475 // cares. This is useful in situations where someone wants to statically link 476 // something like libstdc++, and needs its runtime support routines. 477 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { 478 getDriver().Diag(clang::diag::err_drv_unsupported_opt) 479 << A->getAsString(Args); 480 return; 481 } 482 483 // Otherwise link libSystem, then the dynamic runtime library, and finally any 484 // target specific static runtime library. 485 CmdArgs.push_back("-lSystem"); 486 487 // Select the dynamic runtime library and the target specific static library. 488 const char *DarwinStaticLib = 0; 489 if (isTargetIPhoneOS()) { 490 CmdArgs.push_back("-lgcc_s.1"); 491 492 // We may need some static functions for armv6/thumb which are required to 493 // be in the same linkage unit as their caller. 494 if (getDarwinArchName(Args) == "armv6") 495 DarwinStaticLib = "libclang_rt.armv6.a"; 496 } else { 497 // The dynamic runtime library was merged with libSystem for 10.6 and 498 // beyond; only 10.4 and 10.5 need an additional runtime library. 499 if (isMacosxVersionLT(10, 5)) 500 CmdArgs.push_back("-lgcc_s.10.4"); 501 else if (isMacosxVersionLT(10, 6)) 502 CmdArgs.push_back("-lgcc_s.10.5"); 503 504 // For OS X, we only need a static runtime library when targetting 10.4, to 505 // provide versions of the static functions which were omitted from 506 // 10.4.dylib. 507 if (isMacosxVersionLT(10, 5)) 508 DarwinStaticLib = "libclang_rt.10.4.a"; 509 } 510 511 /// Add the target specific static library, if needed. 512 if (DarwinStaticLib) { 513 llvm::sys::Path P(getDriver().ResourceDir); 514 P.appendComponent("lib"); 515 P.appendComponent("darwin"); 516 P.appendComponent(DarwinStaticLib); 517 518 // For now, allow missing resource libraries to support developers who may 519 // not have compiler-rt checked out or integrated into their build. 520 if (!P.exists()) 521 getDriver().Diag(clang::diag::warn_drv_missing_resource_library) 522 << P.str(); 523 else 524 CmdArgs.push_back(Args.MakeArgString(P.str())); 525 } 526} 527 528void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { 529 const OptTable &Opts = getDriver().getOpts(); 530 531 Arg *OSXVersion = Args.getLastArg(options::OPT_mmacosx_version_min_EQ); 532 Arg *iPhoneVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ); 533 if (OSXVersion && iPhoneVersion) { 534 getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with) 535 << OSXVersion->getAsString(Args) 536 << iPhoneVersion->getAsString(Args); 537 iPhoneVersion = 0; 538 } else if (!OSXVersion && !iPhoneVersion) { 539 // If neither OS X nor iPhoneOS targets were specified, check for 540 // environment defines. 541 const char *OSXTarget = ::getenv("MACOSX_DEPLOYMENT_TARGET"); 542 const char *iPhoneOSTarget = ::getenv("IPHONEOS_DEPLOYMENT_TARGET"); 543 544 // Ignore empty strings. 545 if (OSXTarget && OSXTarget[0] == '\0') 546 OSXTarget = 0; 547 if (iPhoneOSTarget && iPhoneOSTarget[0] == '\0') 548 iPhoneOSTarget = 0; 549 550 // Diagnose conflicting deployment targets, and choose default platform 551 // based on the tool chain. 552 // 553 // FIXME: Don't hardcode default here. 554 if (OSXTarget && iPhoneOSTarget) { 555 // FIXME: We should see if we can get away with warning or erroring on 556 // this. Perhaps put under -pedantic? 557 if (getTriple().getArch() == llvm::Triple::arm || 558 getTriple().getArch() == llvm::Triple::thumb) 559 OSXTarget = 0; 560 else 561 iPhoneOSTarget = 0; 562 } 563 564 if (OSXTarget) { 565 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); 566 OSXVersion = Args.MakeJoinedArg(0, O, OSXTarget); 567 Args.append(OSXVersion); 568 } else if (iPhoneOSTarget) { 569 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); 570 iPhoneVersion = Args.MakeJoinedArg(0, O, iPhoneOSTarget); 571 Args.append(iPhoneVersion); 572 } else { 573 // Otherwise, assume we are targeting OS X. 574 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); 575 OSXVersion = Args.MakeJoinedArg(0, O, MacosxVersionMin); 576 Args.append(OSXVersion); 577 } 578 } 579 580 // Set the tool chain target information. 581 unsigned Major, Minor, Micro; 582 bool HadExtra; 583 if (OSXVersion) { 584 assert(!iPhoneVersion && "Unknown target platform!"); 585 if (!Driver::GetReleaseVersion(OSXVersion->getValue(Args), Major, Minor, 586 Micro, HadExtra) || HadExtra || 587 Major != 10 || Minor >= 10 || Micro >= 10) 588 getDriver().Diag(clang::diag::err_drv_invalid_version_number) 589 << OSXVersion->getAsString(Args); 590 } else { 591 assert(iPhoneVersion && "Unknown target platform!"); 592 if (!Driver::GetReleaseVersion(iPhoneVersion->getValue(Args), Major, Minor, 593 Micro, HadExtra) || HadExtra || 594 Major >= 10 || Minor >= 100 || Micro >= 100) 595 getDriver().Diag(clang::diag::err_drv_invalid_version_number) 596 << iPhoneVersion->getAsString(Args); 597 } 598 setTarget(iPhoneVersion, Major, Minor, Micro); 599} 600 601void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, 602 ArgStringList &CmdArgs) const { 603 CXXStdlibType Type = GetCXXStdlibType(Args); 604 605 switch (Type) { 606 case ToolChain::CST_Libcxx: 607 CmdArgs.push_back("-lc++"); 608 break; 609 610 case ToolChain::CST_Libstdcxx: { 611 // Unfortunately, -lstdc++ doesn't always exist in the standard search path; 612 // it was previously found in the gcc lib dir. However, for all the Darwin 613 // platforms we care about it was -lstdc++.6, so we search for that 614 // explicitly if we can't see an obvious -lstdc++ candidate. 615 616 // Check in the sysroot first. 617 if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { 618 llvm::sys::Path P(A->getValue(Args)); 619 P.appendComponent("usr"); 620 P.appendComponent("lib"); 621 P.appendComponent("libstdc++.dylib"); 622 623 if (!P.exists()) { 624 P.eraseComponent(); 625 P.appendComponent("libstdc++.6.dylib"); 626 if (P.exists()) { 627 CmdArgs.push_back(Args.MakeArgString(P.str())); 628 return; 629 } 630 } 631 } 632 633 // Otherwise, look in the root. 634 if (!llvm::sys::Path("/usr/lib/libstdc++.dylib").exists() && 635 llvm::sys::Path("/usr/lib/libstdc++.6.dylib").exists()) { 636 CmdArgs.push_back("/usr/lib/libstdc++.6.dylib"); 637 return; 638 } 639 640 // Otherwise, let the linker search. 641 CmdArgs.push_back("-lstdc++"); 642 break; 643 } 644 } 645} 646 647void DarwinClang::AddCCKextLibArgs(const ArgList &Args, 648 ArgStringList &CmdArgs) const { 649 650 // For Darwin platforms, use the compiler-rt-based support library 651 // instead of the gcc-provided one (which is also incidentally 652 // only present in the gcc lib dir, which makes it hard to find). 653 654 llvm::sys::Path P(getDriver().ResourceDir); 655 P.appendComponent("lib"); 656 P.appendComponent("darwin"); 657 P.appendComponent("libclang_rt.cc_kext.a"); 658 659 // For now, allow missing resource libraries to support developers who may 660 // not have compiler-rt checked out or integrated into their build. 661 if (!P.exists()) 662 getDriver().Diag(clang::diag::warn_drv_missing_resource_library) 663 << P.str(); 664 else 665 CmdArgs.push_back(Args.MakeArgString(P.str())); 666} 667 668DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args, 669 const char *BoundArch) const { 670 DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs()); 671 const OptTable &Opts = getDriver().getOpts(); 672 673 // FIXME: We really want to get out of the tool chain level argument 674 // translation business, as it makes the driver functionality much 675 // more opaque. For now, we follow gcc closely solely for the 676 // purpose of easily achieving feature parity & testability. Once we 677 // have something that works, we should reevaluate each translation 678 // and try to push it down into tool specific logic. 679 680 for (ArgList::const_iterator it = Args.begin(), 681 ie = Args.end(); it != ie; ++it) { 682 Arg *A = *it; 683 684 if (A->getOption().matches(options::OPT_Xarch__)) { 685 // FIXME: Canonicalize name. 686 if (getArchName() != A->getValue(Args, 0)) 687 continue; 688 689 unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(Args, 1)); 690 unsigned Prev = Index; 691 Arg *XarchArg = Opts.ParseOneArg(Args, Index); 692 693 // If the argument parsing failed or more than one argument was 694 // consumed, the -Xarch_ argument's parameter tried to consume 695 // extra arguments. Emit an error and ignore. 696 // 697 // We also want to disallow any options which would alter the 698 // driver behavior; that isn't going to work in our model. We 699 // use isDriverOption() as an approximation, although things 700 // like -O4 are going to slip through. 701 if (!XarchArg || Index > Prev + 1 || 702 XarchArg->getOption().isDriverOption()) { 703 getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument) 704 << A->getAsString(Args); 705 continue; 706 } 707 708 XarchArg->setBaseArg(A); 709 A = XarchArg; 710 711 DAL->AddSynthesizedArg(A); 712 } 713 714 // Sob. These is strictly gcc compatible for the time being. Apple 715 // gcc translates options twice, which means that self-expanding 716 // options add duplicates. 717 switch ((options::ID) A->getOption().getID()) { 718 default: 719 DAL->append(A); 720 break; 721 722 case options::OPT_mkernel: 723 case options::OPT_fapple_kext: 724 DAL->append(A); 725 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); 726 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); 727 break; 728 729 case options::OPT_dependency_file: 730 DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), 731 A->getValue(Args)); 732 break; 733 734 case options::OPT_gfull: 735 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); 736 DAL->AddFlagArg(A, 737 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols)); 738 break; 739 740 case options::OPT_gused: 741 DAL->AddFlagArg(A, Opts.getOption(options::OPT_g_Flag)); 742 DAL->AddFlagArg(A, 743 Opts.getOption(options::OPT_feliminate_unused_debug_symbols)); 744 break; 745 746 case options::OPT_fterminated_vtables: 747 case options::OPT_findirect_virtual_calls: 748 DAL->AddFlagArg(A, Opts.getOption(options::OPT_fapple_kext)); 749 DAL->AddFlagArg(A, Opts.getOption(options::OPT_static)); 750 break; 751 752 case options::OPT_shared: 753 DAL->AddFlagArg(A, Opts.getOption(options::OPT_dynamiclib)); 754 break; 755 756 case options::OPT_fconstant_cfstrings: 757 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mconstant_cfstrings)); 758 break; 759 760 case options::OPT_fno_constant_cfstrings: 761 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_constant_cfstrings)); 762 break; 763 764 case options::OPT_Wnonportable_cfstrings: 765 DAL->AddFlagArg(A, 766 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings)); 767 break; 768 769 case options::OPT_Wno_nonportable_cfstrings: 770 DAL->AddFlagArg(A, 771 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings)); 772 break; 773 774 case options::OPT_fpascal_strings: 775 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings)); 776 break; 777 778 case options::OPT_fno_pascal_strings: 779 DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings)); 780 break; 781 } 782 } 783 784 if (getTriple().getArch() == llvm::Triple::x86 || 785 getTriple().getArch() == llvm::Triple::x86_64) 786 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) 787 DAL->AddJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), "core2"); 788 789 // Add the arch options based on the particular spelling of -arch, to match 790 // how the driver driver works. 791 if (BoundArch) { 792 llvm::StringRef Name = BoundArch; 793 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ); 794 const Option *MArch = Opts.getOption(options::OPT_march_EQ); 795 796 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, 797 // which defines the list of which architectures we accept. 798 if (Name == "ppc") 799 ; 800 else if (Name == "ppc601") 801 DAL->AddJoinedArg(0, MCpu, "601"); 802 else if (Name == "ppc603") 803 DAL->AddJoinedArg(0, MCpu, "603"); 804 else if (Name == "ppc604") 805 DAL->AddJoinedArg(0, MCpu, "604"); 806 else if (Name == "ppc604e") 807 DAL->AddJoinedArg(0, MCpu, "604e"); 808 else if (Name == "ppc750") 809 DAL->AddJoinedArg(0, MCpu, "750"); 810 else if (Name == "ppc7400") 811 DAL->AddJoinedArg(0, MCpu, "7400"); 812 else if (Name == "ppc7450") 813 DAL->AddJoinedArg(0, MCpu, "7450"); 814 else if (Name == "ppc970") 815 DAL->AddJoinedArg(0, MCpu, "970"); 816 817 else if (Name == "ppc64") 818 DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64)); 819 820 else if (Name == "i386") 821 ; 822 else if (Name == "i486") 823 DAL->AddJoinedArg(0, MArch, "i486"); 824 else if (Name == "i586") 825 DAL->AddJoinedArg(0, MArch, "i586"); 826 else if (Name == "i686") 827 DAL->AddJoinedArg(0, MArch, "i686"); 828 else if (Name == "pentium") 829 DAL->AddJoinedArg(0, MArch, "pentium"); 830 else if (Name == "pentium2") 831 DAL->AddJoinedArg(0, MArch, "pentium2"); 832 else if (Name == "pentpro") 833 DAL->AddJoinedArg(0, MArch, "pentiumpro"); 834 else if (Name == "pentIIm3") 835 DAL->AddJoinedArg(0, MArch, "pentium2"); 836 837 else if (Name == "x86_64") 838 DAL->AddFlagArg(0, Opts.getOption(options::OPT_m64)); 839 840 else if (Name == "arm") 841 DAL->AddJoinedArg(0, MArch, "armv4t"); 842 else if (Name == "armv4t") 843 DAL->AddJoinedArg(0, MArch, "armv4t"); 844 else if (Name == "armv5") 845 DAL->AddJoinedArg(0, MArch, "armv5tej"); 846 else if (Name == "xscale") 847 DAL->AddJoinedArg(0, MArch, "xscale"); 848 else if (Name == "armv6") 849 DAL->AddJoinedArg(0, MArch, "armv6k"); 850 else if (Name == "armv7") 851 DAL->AddJoinedArg(0, MArch, "armv7a"); 852 853 else 854 llvm_unreachable("invalid Darwin arch"); 855 } 856 857 // Add an explicit version min argument for the deployment target. We do this 858 // after argument translation because -Xarch_ arguments may add a version min 859 // argument. 860 AddDeploymentTarget(*DAL); 861 862 return DAL; 863} 864 865bool Darwin::IsUnwindTablesDefault() const { 866 // FIXME: Gross; we should probably have some separate target 867 // definition, possibly even reusing the one in clang. 868 return getArchName() == "x86_64"; 869} 870 871bool Darwin::UseDwarfDebugFlags() const { 872 if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) 873 return S[0] != '\0'; 874 return false; 875} 876 877bool Darwin::UseSjLjExceptions() const { 878 // Darwin uses SjLj exceptions on ARM. 879 return (getTriple().getArch() == llvm::Triple::arm || 880 getTriple().getArch() == llvm::Triple::thumb); 881} 882 883const char *Darwin::GetDefaultRelocationModel() const { 884 return "pic"; 885} 886 887const char *Darwin::GetForcedPicModel() const { 888 if (getArchName() == "x86_64") 889 return "pic"; 890 return 0; 891} 892 893bool Darwin::SupportsObjCGC() const { 894 // Garbage collection is supported everywhere except on iPhone OS. 895 return !isTargetIPhoneOS(); 896} 897 898std::string 899Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args) const { 900 return ComputeLLVMTriple(Args); 901} 902 903/// Generic_GCC - A tool chain using the 'gcc' command to perform 904/// all subcommands; this relies on gcc translating the majority of 905/// command line options. 906 907Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) 908 : ToolChain(Host, Triple) { 909 getProgramPaths().push_back(getDriver().getInstalledDir()); 910 if (getDriver().getInstalledDir() != getDriver().Dir.c_str()) 911 getProgramPaths().push_back(getDriver().Dir); 912} 913 914Generic_GCC::~Generic_GCC() { 915 // Free tool implementations. 916 for (llvm::DenseMap<unsigned, Tool*>::iterator 917 it = Tools.begin(), ie = Tools.end(); it != ie; ++it) 918 delete it->second; 919} 920 921Tool &Generic_GCC::SelectTool(const Compilation &C, 922 const JobAction &JA) const { 923 Action::ActionClass Key; 924 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 925 Key = Action::AnalyzeJobClass; 926 else 927 Key = JA.getKind(); 928 929 Tool *&T = Tools[Key]; 930 if (!T) { 931 switch (Key) { 932 case Action::InputClass: 933 case Action::BindArchClass: 934 assert(0 && "Invalid tool kind."); 935 case Action::PreprocessJobClass: 936 T = new tools::gcc::Preprocess(*this); break; 937 case Action::PrecompileJobClass: 938 T = new tools::gcc::Precompile(*this); break; 939 case Action::AnalyzeJobClass: 940 T = new tools::Clang(*this); break; 941 case Action::CompileJobClass: 942 T = new tools::gcc::Compile(*this); break; 943 case Action::AssembleJobClass: 944 T = new tools::gcc::Assemble(*this); break; 945 case Action::LinkJobClass: 946 T = new tools::gcc::Link(*this); break; 947 948 // This is a bit ungeneric, but the only platform using a driver 949 // driver is Darwin. 950 case Action::LipoJobClass: 951 T = new tools::darwin::Lipo(*this); break; 952 case Action::DsymutilJobClass: 953 T = new tools::darwin::Dsymutil(*this); break; 954 } 955 } 956 957 return *T; 958} 959 960bool Generic_GCC::IsUnwindTablesDefault() const { 961 // FIXME: Gross; we should probably have some separate target 962 // definition, possibly even reusing the one in clang. 963 return getArchName() == "x86_64"; 964} 965 966const char *Generic_GCC::GetDefaultRelocationModel() const { 967 return "static"; 968} 969 970const char *Generic_GCC::GetForcedPicModel() const { 971 return 0; 972} 973 974/// TCEToolChain - A tool chain using the llvm bitcode tools to perform 975/// all subcommands. See http://tce.cs.tut.fi for our peculiar target. 976/// Currently does not support anything else but compilation. 977 978TCEToolChain::TCEToolChain(const HostInfo &Host, const llvm::Triple& Triple) 979 : ToolChain(Host, Triple) { 980 // Path mangling to find libexec 981 std::string Path(getDriver().Dir); 982 983 Path += "/../libexec"; 984 getProgramPaths().push_back(Path); 985} 986 987TCEToolChain::~TCEToolChain() { 988 for (llvm::DenseMap<unsigned, Tool*>::iterator 989 it = Tools.begin(), ie = Tools.end(); it != ie; ++it) 990 delete it->second; 991} 992 993bool TCEToolChain::IsMathErrnoDefault() const { 994 return true; 995} 996 997bool TCEToolChain::IsUnwindTablesDefault() const { 998 return false; 999} 1000 1001const char *TCEToolChain::GetDefaultRelocationModel() const { 1002 return "static"; 1003} 1004 1005const char *TCEToolChain::GetForcedPicModel() const { 1006 return 0; 1007} 1008 1009Tool &TCEToolChain::SelectTool(const Compilation &C, 1010 const JobAction &JA) const { 1011 Action::ActionClass Key; 1012 Key = Action::AnalyzeJobClass; 1013 1014 Tool *&T = Tools[Key]; 1015 if (!T) { 1016 switch (Key) { 1017 case Action::PreprocessJobClass: 1018 T = new tools::gcc::Preprocess(*this); break; 1019 case Action::AnalyzeJobClass: 1020 T = new tools::Clang(*this); break; 1021 default: 1022 assert(false && "Unsupported action for TCE target."); 1023 } 1024 } 1025 return *T; 1026} 1027 1028/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. 1029 1030OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple) 1031 : Generic_GCC(Host, Triple) { 1032 getFilePaths().push_back(getDriver().Dir + "/../lib"); 1033 getFilePaths().push_back("/usr/lib"); 1034} 1035 1036Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const { 1037 Action::ActionClass Key; 1038 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 1039 Key = Action::AnalyzeJobClass; 1040 else 1041 Key = JA.getKind(); 1042 1043 Tool *&T = Tools[Key]; 1044 if (!T) { 1045 switch (Key) { 1046 case Action::AssembleJobClass: 1047 T = new tools::openbsd::Assemble(*this); break; 1048 case Action::LinkJobClass: 1049 T = new tools::openbsd::Link(*this); break; 1050 default: 1051 T = &Generic_GCC::SelectTool(C, JA); 1052 } 1053 } 1054 1055 return *T; 1056} 1057 1058/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. 1059 1060FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple) 1061 : Generic_GCC(Host, Triple) { 1062 1063 // Determine if we are compiling 32-bit code on an x86_64 platform. 1064 bool Lib32 = false; 1065 if (Triple.getArch() == llvm::Triple::x86 && 1066 llvm::Triple(getDriver().DefaultHostTriple).getArch() == 1067 llvm::Triple::x86_64) 1068 Lib32 = true; 1069 1070 getProgramPaths().push_back(getDriver().Dir + "/../libexec"); 1071 getProgramPaths().push_back("/usr/libexec"); 1072 if (Lib32) { 1073 getFilePaths().push_back(getDriver().Dir + "/../lib32"); 1074 getFilePaths().push_back("/usr/lib32"); 1075 } else { 1076 getFilePaths().push_back(getDriver().Dir + "/../lib"); 1077 getFilePaths().push_back("/usr/lib"); 1078 } 1079} 1080 1081Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { 1082 Action::ActionClass Key; 1083 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 1084 Key = Action::AnalyzeJobClass; 1085 else 1086 Key = JA.getKind(); 1087 1088 Tool *&T = Tools[Key]; 1089 if (!T) { 1090 switch (Key) { 1091 case Action::AssembleJobClass: 1092 T = new tools::freebsd::Assemble(*this); break; 1093 case Action::LinkJobClass: 1094 T = new tools::freebsd::Link(*this); break; 1095 default: 1096 T = &Generic_GCC::SelectTool(C, JA); 1097 } 1098 } 1099 1100 return *T; 1101} 1102 1103/// Minix - Minix tool chain which can call as(1) and ld(1) directly. 1104 1105Minix::Minix(const HostInfo &Host, const llvm::Triple& Triple) 1106 : Generic_GCC(Host, Triple) { 1107 getFilePaths().push_back(getDriver().Dir + "/../lib"); 1108 getFilePaths().push_back("/usr/lib"); 1109 getFilePaths().push_back("/usr/gnu/lib"); 1110 getFilePaths().push_back("/usr/gnu/lib/gcc/i686-pc-minix/4.4.3"); 1111} 1112 1113Tool &Minix::SelectTool(const Compilation &C, const JobAction &JA) const { 1114 Action::ActionClass Key; 1115 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 1116 Key = Action::AnalyzeJobClass; 1117 else 1118 Key = JA.getKind(); 1119 1120 Tool *&T = Tools[Key]; 1121 if (!T) { 1122 switch (Key) { 1123 case Action::AssembleJobClass: 1124 T = new tools::minix::Assemble(*this); break; 1125 case Action::LinkJobClass: 1126 T = new tools::minix::Link(*this); break; 1127 default: 1128 T = &Generic_GCC::SelectTool(C, JA); 1129 } 1130 } 1131 1132 return *T; 1133} 1134 1135/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly. 1136 1137AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple) 1138 : Generic_GCC(Host, Triple) { 1139 1140 getProgramPaths().push_back(getDriver().getInstalledDir()); 1141 if (getDriver().getInstalledDir() != getDriver().Dir.c_str()) 1142 getProgramPaths().push_back(getDriver().Dir); 1143 1144 getFilePaths().push_back(getDriver().Dir + "/../lib"); 1145 getFilePaths().push_back("/usr/lib"); 1146 getFilePaths().push_back("/usr/sfw/lib"); 1147 getFilePaths().push_back("/opt/gcc4/lib"); 1148 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4"); 1149 1150} 1151 1152Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const { 1153 Action::ActionClass Key; 1154 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 1155 Key = Action::AnalyzeJobClass; 1156 else 1157 Key = JA.getKind(); 1158 1159 Tool *&T = Tools[Key]; 1160 if (!T) { 1161 switch (Key) { 1162 case Action::AssembleJobClass: 1163 T = new tools::auroraux::Assemble(*this); break; 1164 case Action::LinkJobClass: 1165 T = new tools::auroraux::Link(*this); break; 1166 default: 1167 T = &Generic_GCC::SelectTool(C, JA); 1168 } 1169 } 1170 1171 return *T; 1172} 1173 1174 1175/// Linux toolchain (very bare-bones at the moment). 1176 1177Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple) 1178 : Generic_GCC(Host, Triple) { 1179 getFilePaths().push_back(getDriver().Dir + 1180 "/../lib/clang/" CLANG_VERSION_STRING "/"); 1181 getFilePaths().push_back("/lib/"); 1182 getFilePaths().push_back("/usr/lib/"); 1183 1184 // Depending on the Linux distribution, any combination of lib{,32,64} is 1185 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems, 1186 // openSUSE uses lib and lib64 for the same purpose. 1187 getFilePaths().push_back("/lib32/"); 1188 getFilePaths().push_back("/usr/lib32/"); 1189 getFilePaths().push_back("/lib64/"); 1190 getFilePaths().push_back("/usr/lib64/"); 1191 1192 // FIXME: Figure out some way to get gcc's libdir 1193 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need 1194 // crtbegin.o/crtend.o/etc., and want static versions of various 1195 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably 1196 // get away with using shared versions in /usr/lib, though. 1197 // We could fall back to the approach we used for includes (a massive 1198 // list), but that's messy at best. 1199} 1200 1201Tool &Linux::SelectTool(const Compilation &C, const JobAction &JA) const { 1202 Action::ActionClass Key; 1203 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 1204 Key = Action::AnalyzeJobClass; 1205 else 1206 Key = JA.getKind(); 1207 1208 Tool *&T = Tools[Key]; 1209 if (!T) { 1210 switch (Key) { 1211 case Action::AssembleJobClass: 1212 T = new tools::linuxtools::Assemble(*this); break; 1213 default: 1214 T = &Generic_GCC::SelectTool(C, JA); 1215 } 1216 } 1217 1218 return *T; 1219} 1220 1221/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. 1222 1223DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple) 1224 : Generic_GCC(Host, Triple) { 1225 1226 // Path mangling to find libexec 1227 getProgramPaths().push_back(getDriver().getInstalledDir()); 1228 if (getDriver().getInstalledDir() != getDriver().Dir.c_str()) 1229 getProgramPaths().push_back(getDriver().Dir); 1230 1231 getFilePaths().push_back(getDriver().Dir + "/../lib"); 1232 getFilePaths().push_back("/usr/lib"); 1233 getFilePaths().push_back("/usr/lib/gcc41"); 1234} 1235 1236Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const { 1237 Action::ActionClass Key; 1238 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 1239 Key = Action::AnalyzeJobClass; 1240 else 1241 Key = JA.getKind(); 1242 1243 Tool *&T = Tools[Key]; 1244 if (!T) { 1245 switch (Key) { 1246 case Action::AssembleJobClass: 1247 T = new tools::dragonfly::Assemble(*this); break; 1248 case Action::LinkJobClass: 1249 T = new tools::dragonfly::Link(*this); break; 1250 default: 1251 T = &Generic_GCC::SelectTool(C, JA); 1252 } 1253 } 1254 1255 return *T; 1256} 1257 1258Windows::Windows(const HostInfo &Host, const llvm::Triple& Triple) 1259 : ToolChain(Host, Triple) { 1260} 1261 1262Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA) const { 1263 Action::ActionClass Key; 1264 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 1265 Key = Action::AnalyzeJobClass; 1266 else 1267 Key = JA.getKind(); 1268 1269 Tool *&T = Tools[Key]; 1270 if (!T) { 1271 switch (Key) { 1272 case Action::InputClass: 1273 case Action::BindArchClass: 1274 case Action::LipoJobClass: 1275 case Action::DsymutilJobClass: 1276 assert(0 && "Invalid tool kind."); 1277 case Action::PreprocessJobClass: 1278 case Action::PrecompileJobClass: 1279 case Action::AnalyzeJobClass: 1280 case Action::CompileJobClass: 1281 T = new tools::Clang(*this); break; 1282 case Action::AssembleJobClass: 1283 T = new tools::ClangAs(*this); break; 1284 case Action::LinkJobClass: 1285 T = new tools::visualstudio::Link(*this); break; 1286 } 1287 } 1288 1289 return *T; 1290} 1291 1292bool Windows::IsIntegratedAssemblerDefault() const { 1293 return true; 1294} 1295 1296bool Windows::IsUnwindTablesDefault() const { 1297 // FIXME: Gross; we should probably have some separate target 1298 // definition, possibly even reusing the one in clang. 1299 return getArchName() == "x86_64"; 1300} 1301 1302const char *Windows::GetDefaultRelocationModel() const { 1303 return "static"; 1304} 1305 1306const char *Windows::GetForcedPicModel() const { 1307 if (getArchName() == "x86_64") 1308 return "pic"; 1309 return 0; 1310} 1311