ToolChains.cpp revision 199512
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/Driver.h" 15#include "clang/Driver/DriverDiagnostic.h" 16#include "clang/Driver/HostInfo.h" 17#include "clang/Driver/OptTable.h" 18#include "clang/Driver/Option.h" 19#include "clang/Driver/Options.h" 20 21#include "llvm/ADT/StringExtras.h" 22#include "llvm/Support/ErrorHandling.h" 23#include "llvm/Support/raw_ostream.h" 24#include "llvm/System/Path.h" 25 26#include <cstdlib> // ::getenv 27 28using namespace clang::driver; 29using namespace clang::driver::toolchains; 30 31/// Darwin - Darwin tool chain for i386 and x86_64. 32 33Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple, 34 const unsigned (&_DarwinVersion)[3], bool _IsIPhoneOS) 35 : ToolChain(Host, Triple), 36 IsIPhoneOS(_IsIPhoneOS) 37{ 38 DarwinVersion[0] = _DarwinVersion[0]; 39 DarwinVersion[1] = _DarwinVersion[1]; 40 DarwinVersion[2] = _DarwinVersion[2]; 41 42 llvm::raw_string_ostream(MacosxVersionMin) 43 << "10." << std::max(0, (int)DarwinVersion[0] - 4) << '.' 44 << DarwinVersion[1]; 45 46 // FIXME: Lift default up. 47 IPhoneOSVersionMin = "3.0"; 48} 49 50DarwinGCC::DarwinGCC(const HostInfo &Host, const llvm::Triple& Triple, 51 const unsigned (&DarwinVersion)[3], 52 const unsigned (&_GCCVersion)[3], bool IsIPhoneOS) 53 : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS) 54{ 55 GCCVersion[0] = _GCCVersion[0]; 56 GCCVersion[1] = _GCCVersion[1]; 57 GCCVersion[2] = _GCCVersion[2]; 58 59 // Set up the tool chain paths to match gcc. 60 ToolChainDir = "i686-apple-darwin"; 61 ToolChainDir += llvm::utostr(DarwinVersion[0]); 62 ToolChainDir += "/"; 63 ToolChainDir += llvm::utostr(GCCVersion[0]); 64 ToolChainDir += '.'; 65 ToolChainDir += llvm::utostr(GCCVersion[1]); 66 ToolChainDir += '.'; 67 ToolChainDir += llvm::utostr(GCCVersion[2]); 68 69 // Try the next major version if that tool chain dir is invalid. 70 std::string Tmp = "/usr/lib/gcc/" + ToolChainDir; 71 if (!llvm::sys::Path(Tmp).exists()) { 72 std::string Next = "i686-apple-darwin"; 73 Next += llvm::utostr(DarwinVersion[0] + 1); 74 Next += "/"; 75 Next += llvm::utostr(GCCVersion[0]); 76 Next += '.'; 77 Next += llvm::utostr(GCCVersion[1]); 78 Next += '.'; 79 Next += llvm::utostr(GCCVersion[2]); 80 81 // Use that if it exists, otherwise hope the user isn't linking. 82 // 83 // FIXME: Drop dependency on gcc's tool chain. 84 Tmp = "/usr/lib/gcc/" + Next; 85 if (llvm::sys::Path(Tmp).exists()) 86 ToolChainDir = Next; 87 } 88 89 std::string Path; 90 if (getArchName() == "x86_64") { 91 Path = getHost().getDriver().Dir; 92 Path += "/../lib/gcc/"; 93 Path += ToolChainDir; 94 Path += "/x86_64"; 95 getFilePaths().push_back(Path); 96 97 Path = "/usr/lib/gcc/"; 98 Path += ToolChainDir; 99 Path += "/x86_64"; 100 getFilePaths().push_back(Path); 101 } 102 103 Path = getHost().getDriver().Dir; 104 Path += "/../lib/gcc/"; 105 Path += ToolChainDir; 106 getFilePaths().push_back(Path); 107 108 Path = "/usr/lib/gcc/"; 109 Path += ToolChainDir; 110 getFilePaths().push_back(Path); 111 112 Path = getHost().getDriver().Dir; 113 Path += "/../libexec/gcc/"; 114 Path += ToolChainDir; 115 getProgramPaths().push_back(Path); 116 117 Path = "/usr/libexec/gcc/"; 118 Path += ToolChainDir; 119 getProgramPaths().push_back(Path); 120 121 Path = getHost().getDriver().Dir; 122 Path += "/../libexec"; 123 getProgramPaths().push_back(Path); 124 125 getProgramPaths().push_back(getHost().getDriver().Dir); 126} 127 128Darwin::~Darwin() { 129 // Free tool implementations. 130 for (llvm::DenseMap<unsigned, Tool*>::iterator 131 it = Tools.begin(), ie = Tools.end(); it != ie; ++it) 132 delete it->second; 133} 134 135Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const { 136 Action::ActionClass Key; 137 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 138 Key = Action::AnalyzeJobClass; 139 else 140 Key = JA.getKind(); 141 142 Tool *&T = Tools[Key]; 143 if (!T) { 144 switch (Key) { 145 case Action::InputClass: 146 case Action::BindArchClass: 147 assert(0 && "Invalid tool kind."); 148 case Action::PreprocessJobClass: 149 T = new tools::darwin::Preprocess(*this); break; 150 case Action::AnalyzeJobClass: 151 T = new tools::Clang(*this); break; 152 case Action::PrecompileJobClass: 153 case Action::CompileJobClass: 154 T = new tools::darwin::Compile(*this); break; 155 case Action::AssembleJobClass: 156 T = new tools::darwin::Assemble(*this); break; 157 case Action::LinkJobClass: 158 T = new tools::darwin::Link(*this); break; 159 case Action::LipoJobClass: 160 T = new tools::darwin::Lipo(*this); break; 161 } 162 } 163 164 return *T; 165} 166 167void DarwinGCC::AddLinkSearchPathArgs(const ArgList &Args, 168 ArgStringList &CmdArgs) const { 169 // FIXME: Derive these correctly. 170 if (getArchName() == "x86_64") { 171 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + 172 "/x86_64")); 173 // Intentionally duplicated for (temporary) gcc bug compatibility. 174 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + 175 "/x86_64")); 176 } 177 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/" + ToolChainDir)); 178 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); 179 // Intentionally duplicated for (temporary) gcc bug compatibility. 180 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir)); 181 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + 182 "/../../../" + ToolChainDir)); 183 CmdArgs.push_back(Args.MakeArgString("-L/usr/lib/gcc/" + ToolChainDir + 184 "/../../..")); 185} 186 187void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args, 188 ArgStringList &CmdArgs) const { 189 unsigned MacosxVersionMin[3]; 190 getMacosxVersionMin(Args, MacosxVersionMin); 191 192 // Derived from libgcc and lib specs but refactored. 193 if (Args.hasArg(options::OPT_static)) { 194 CmdArgs.push_back("-lgcc_static"); 195 } else { 196 if (Args.hasArg(options::OPT_static_libgcc)) { 197 CmdArgs.push_back("-lgcc_eh"); 198 } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { 199 // Derived from darwin_iphoneos_libgcc spec. 200 if (isIPhoneOS()) { 201 CmdArgs.push_back("-lgcc_s.1"); 202 } else { 203 CmdArgs.push_back("-lgcc_s.10.5"); 204 } 205 } else if (Args.hasArg(options::OPT_shared_libgcc) || 206 // FIXME: -fexceptions -fno-exceptions means no exceptions 207 Args.hasArg(options::OPT_fexceptions) || 208 Args.hasArg(options::OPT_fgnu_runtime)) { 209 // FIXME: This is probably broken on 10.3? 210 if (isMacosxVersionLT(MacosxVersionMin, 10, 5)) 211 CmdArgs.push_back("-lgcc_s.10.4"); 212 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6)) 213 CmdArgs.push_back("-lgcc_s.10.5"); 214 } else { 215 if (isMacosxVersionLT(MacosxVersionMin, 10, 3, 9)) 216 ; // Do nothing. 217 else if (isMacosxVersionLT(MacosxVersionMin, 10, 5)) 218 CmdArgs.push_back("-lgcc_s.10.4"); 219 else if (isMacosxVersionLT(MacosxVersionMin, 10, 6)) 220 CmdArgs.push_back("-lgcc_s.10.5"); 221 } 222 223 if (isIPhoneOS() || isMacosxVersionLT(MacosxVersionMin, 10, 6)) { 224 CmdArgs.push_back("-lgcc"); 225 CmdArgs.push_back("-lSystem"); 226 } else { 227 CmdArgs.push_back("-lSystem"); 228 CmdArgs.push_back("-lgcc"); 229 } 230 } 231} 232 233DarwinClang::DarwinClang(const HostInfo &Host, const llvm::Triple& Triple, 234 const unsigned (&DarwinVersion)[3], 235 bool IsIPhoneOS) 236 : Darwin(Host, Triple, DarwinVersion, IsIPhoneOS) 237{ 238 // Add the relative libexec dir (for clang-cc). 239 // 240 // FIXME: We should sink clang-cc into libexec/clang/<version>/. 241 std::string Path = getHost().getDriver().Dir; 242 Path += "/../libexec"; 243 getProgramPaths().push_back(Path); 244 245 // We expect 'as', 'ld', etc. to be adjacent to our install dir. 246 getProgramPaths().push_back(getHost().getDriver().Dir); 247} 248 249void DarwinClang::AddLinkSearchPathArgs(const ArgList &Args, 250 ArgStringList &CmdArgs) const { 251 // The Clang toolchain uses explicit paths for internal libraries. 252} 253 254void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args, 255 ArgStringList &CmdArgs) const { 256 // Check for static linking. 257 if (Args.hasArg(options::OPT_static)) { 258 // FIXME: We need to have compiler-rt available (perhaps as 259 // libclang_static.a) to link against. 260 return; 261 } 262 263 // Reject -static-libgcc for now, we can deal with this when and if someone 264 // cares. This is useful in situations where someone wants to statically link 265 // something like libstdc++, and needs its runtime support routines. 266 if (const Arg *A = Args.getLastArg(options::OPT_static_libgcc)) { 267 getHost().getDriver().Diag(clang::diag::err_drv_unsupported_opt) 268 << A->getAsString(Args); 269 return; 270 } 271 272 // Otherwise link libSystem, which should have the support routines. 273 // 274 // FIXME: This is only true for 10.6 and beyond. Legacy support isn't 275 // critical, but it should work... we should just link in the static 276 // compiler-rt library. 277 CmdArgs.push_back("-lSystem"); 278} 279 280void Darwin::getMacosxVersionMin(const ArgList &Args, 281 unsigned (&Res)[3]) const { 282 if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) { 283 bool HadExtra; 284 if (!Driver::GetReleaseVersion(A->getValue(Args), Res[0], Res[1], Res[2], 285 HadExtra) || 286 HadExtra) { 287 const Driver &D = getHost().getDriver(); 288 D.Diag(clang::diag::err_drv_invalid_version_number) 289 << A->getAsString(Args); 290 } 291 } else 292 return getMacosxVersion(Res); 293} 294 295DerivedArgList *Darwin::TranslateArgs(InputArgList &Args, 296 const char *BoundArch) const { 297 DerivedArgList *DAL = new DerivedArgList(Args, false); 298 const OptTable &Opts = getHost().getDriver().getOpts(); 299 300 // FIXME: We really want to get out of the tool chain level argument 301 // translation business, as it makes the driver functionality much 302 // more opaque. For now, we follow gcc closely solely for the 303 // purpose of easily achieving feature parity & testability. Once we 304 // have something that works, we should reevaluate each translation 305 // and try to push it down into tool specific logic. 306 307 Arg *OSXVersion = 308 Args.getLastArgNoClaim(options::OPT_mmacosx_version_min_EQ); 309 Arg *iPhoneVersion = 310 Args.getLastArgNoClaim(options::OPT_miphoneos_version_min_EQ); 311 if (OSXVersion && iPhoneVersion) { 312 getHost().getDriver().Diag(clang::diag::err_drv_argument_not_allowed_with) 313 << OSXVersion->getAsString(Args) 314 << iPhoneVersion->getAsString(Args); 315 } else if (!OSXVersion && !iPhoneVersion) { 316 // Chose the default version based on the arch. 317 // 318 // FIXME: Are there iPhone overrides for this? 319 320 if (!isIPhoneOS()) { 321 // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version 322 // from the host. 323 const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET"); 324 if (!Version) 325 Version = MacosxVersionMin.c_str(); 326 const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ); 327 DAL->append(DAL->MakeJoinedArg(0, O, Version)); 328 } else { 329 const char *Version = IPhoneOSVersionMin.c_str(); 330 const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ); 331 DAL->append(DAL->MakeJoinedArg(0, O, Version)); 332 } 333 } 334 335 for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) { 336 Arg *A = *it; 337 338 if (A->getOption().matches(options::OPT_Xarch__)) { 339 // FIXME: Canonicalize name. 340 if (getArchName() != A->getValue(Args, 0)) 341 continue; 342 343 // FIXME: The arg is leaked here, and we should have a nicer 344 // interface for this. 345 unsigned Prev, Index = Prev = A->getIndex() + 1; 346 Arg *XarchArg = Opts.ParseOneArg(Args, Index); 347 348 // If the argument parsing failed or more than one argument was 349 // consumed, the -Xarch_ argument's parameter tried to consume 350 // extra arguments. Emit an error and ignore. 351 // 352 // We also want to disallow any options which would alter the 353 // driver behavior; that isn't going to work in our model. We 354 // use isDriverOption() as an approximation, although things 355 // like -O4 are going to slip through. 356 if (!XarchArg || Index > Prev + 1 || 357 XarchArg->getOption().isDriverOption()) { 358 getHost().getDriver().Diag(clang::diag::err_drv_invalid_Xarch_argument) 359 << A->getAsString(Args); 360 continue; 361 } 362 363 XarchArg->setBaseArg(A); 364 A = XarchArg; 365 } 366 367 // Sob. These is strictly gcc compatible for the time being. Apple 368 // gcc translates options twice, which means that self-expanding 369 // options add duplicates. 370 switch ((options::ID) A->getOption().getID()) { 371 default: 372 DAL->append(A); 373 break; 374 375 case options::OPT_mkernel: 376 case options::OPT_fapple_kext: 377 DAL->append(A); 378 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); 379 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); 380 break; 381 382 case options::OPT_dependency_file: 383 DAL->append(DAL->MakeSeparateArg(A, Opts.getOption(options::OPT_MF), 384 A->getValue(Args))); 385 break; 386 387 case options::OPT_gfull: 388 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag))); 389 DAL->append(DAL->MakeFlagArg(A, 390 Opts.getOption(options::OPT_fno_eliminate_unused_debug_symbols))); 391 break; 392 393 case options::OPT_gused: 394 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_g_Flag))); 395 DAL->append(DAL->MakeFlagArg(A, 396 Opts.getOption(options::OPT_feliminate_unused_debug_symbols))); 397 break; 398 399 case options::OPT_fterminated_vtables: 400 case options::OPT_findirect_virtual_calls: 401 DAL->append(DAL->MakeFlagArg(A, 402 Opts.getOption(options::OPT_fapple_kext))); 403 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_static))); 404 break; 405 406 case options::OPT_shared: 407 DAL->append(DAL->MakeFlagArg(A, Opts.getOption(options::OPT_dynamiclib))); 408 break; 409 410 case options::OPT_fconstant_cfstrings: 411 DAL->append(DAL->MakeFlagArg(A, 412 Opts.getOption(options::OPT_mconstant_cfstrings))); 413 break; 414 415 case options::OPT_fno_constant_cfstrings: 416 DAL->append(DAL->MakeFlagArg(A, 417 Opts.getOption(options::OPT_mno_constant_cfstrings))); 418 break; 419 420 case options::OPT_Wnonportable_cfstrings: 421 DAL->append(DAL->MakeFlagArg(A, 422 Opts.getOption(options::OPT_mwarn_nonportable_cfstrings))); 423 break; 424 425 case options::OPT_Wno_nonportable_cfstrings: 426 DAL->append(DAL->MakeFlagArg(A, 427 Opts.getOption(options::OPT_mno_warn_nonportable_cfstrings))); 428 break; 429 430 case options::OPT_fpascal_strings: 431 DAL->append(DAL->MakeFlagArg(A, 432 Opts.getOption(options::OPT_mpascal_strings))); 433 break; 434 435 case options::OPT_fno_pascal_strings: 436 DAL->append(DAL->MakeFlagArg(A, 437 Opts.getOption(options::OPT_mno_pascal_strings))); 438 break; 439 } 440 } 441 442 if (getTriple().getArch() == llvm::Triple::x86 || 443 getTriple().getArch() == llvm::Triple::x86_64) 444 if (!Args.hasArgNoClaim(options::OPT_mtune_EQ)) 445 DAL->append(DAL->MakeJoinedArg(0, Opts.getOption(options::OPT_mtune_EQ), 446 "core2")); 447 448 // Add the arch options based on the particular spelling of -arch, to match 449 // how the driver driver works. 450 if (BoundArch) { 451 llvm::StringRef Name = BoundArch; 452 const Option *MCpu = Opts.getOption(options::OPT_mcpu_EQ); 453 const Option *MArch = Opts.getOption(options::OPT_march_EQ); 454 455 // This code must be kept in sync with LLVM's getArchTypeForDarwinArch, 456 // which defines the list of which architectures we accept. 457 if (Name == "ppc") 458 ; 459 else if (Name == "ppc601") 460 DAL->append(DAL->MakeJoinedArg(0, MCpu, "601")); 461 else if (Name == "ppc603") 462 DAL->append(DAL->MakeJoinedArg(0, MCpu, "603")); 463 else if (Name == "ppc604") 464 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604")); 465 else if (Name == "ppc604e") 466 DAL->append(DAL->MakeJoinedArg(0, MCpu, "604e")); 467 else if (Name == "ppc750") 468 DAL->append(DAL->MakeJoinedArg(0, MCpu, "750")); 469 else if (Name == "ppc7400") 470 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7400")); 471 else if (Name == "ppc7450") 472 DAL->append(DAL->MakeJoinedArg(0, MCpu, "7450")); 473 else if (Name == "ppc970") 474 DAL->append(DAL->MakeJoinedArg(0, MCpu, "970")); 475 476 else if (Name == "ppc64") 477 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64))); 478 479 else if (Name == "i386") 480 ; 481 else if (Name == "i486") 482 DAL->append(DAL->MakeJoinedArg(0, MArch, "i486")); 483 else if (Name == "i586") 484 DAL->append(DAL->MakeJoinedArg(0, MArch, "i586")); 485 else if (Name == "i686") 486 DAL->append(DAL->MakeJoinedArg(0, MArch, "i686")); 487 else if (Name == "pentium") 488 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium")); 489 else if (Name == "pentium2") 490 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2")); 491 else if (Name == "pentpro") 492 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentiumpro")); 493 else if (Name == "pentIIm3") 494 DAL->append(DAL->MakeJoinedArg(0, MArch, "pentium2")); 495 496 else if (Name == "x86_64") 497 DAL->append(DAL->MakeFlagArg(0, Opts.getOption(options::OPT_m64))); 498 499 else if (Name == "arm") 500 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t")); 501 else if (Name == "armv4t") 502 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv4t")); 503 else if (Name == "armv5") 504 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv5tej")); 505 else if (Name == "xscale") 506 DAL->append(DAL->MakeJoinedArg(0, MArch, "xscale")); 507 else if (Name == "armv6") 508 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv6k")); 509 else if (Name == "armv7") 510 DAL->append(DAL->MakeJoinedArg(0, MArch, "armv7a")); 511 512 else 513 llvm::llvm_unreachable("invalid Darwin arch"); 514 } 515 516 return DAL; 517} 518 519bool Darwin::IsMathErrnoDefault() const { 520 return false; 521} 522 523bool Darwin::IsUnwindTablesDefault() const { 524 // FIXME: Gross; we should probably have some separate target 525 // definition, possibly even reusing the one in clang. 526 return getArchName() == "x86_64"; 527} 528 529const char *Darwin::GetDefaultRelocationModel() const { 530 return "pic"; 531} 532 533const char *Darwin::GetForcedPicModel() const { 534 if (getArchName() == "x86_64") 535 return "pic"; 536 return 0; 537} 538 539/// Generic_GCC - A tool chain using the 'gcc' command to perform 540/// all subcommands; this relies on gcc translating the majority of 541/// command line options. 542 543Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) 544 : ToolChain(Host, Triple) { 545 std::string Path(getHost().getDriver().Dir); 546 Path += "/../libexec"; 547 getProgramPaths().push_back(Path); 548 549 getProgramPaths().push_back(getHost().getDriver().Dir); 550} 551 552Generic_GCC::~Generic_GCC() { 553 // Free tool implementations. 554 for (llvm::DenseMap<unsigned, Tool*>::iterator 555 it = Tools.begin(), ie = Tools.end(); it != ie; ++it) 556 delete it->second; 557} 558 559Tool &Generic_GCC::SelectTool(const Compilation &C, 560 const JobAction &JA) const { 561 Action::ActionClass Key; 562 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 563 Key = Action::AnalyzeJobClass; 564 else 565 Key = JA.getKind(); 566 567 Tool *&T = Tools[Key]; 568 if (!T) { 569 switch (Key) { 570 case Action::InputClass: 571 case Action::BindArchClass: 572 assert(0 && "Invalid tool kind."); 573 case Action::PreprocessJobClass: 574 T = new tools::gcc::Preprocess(*this); break; 575 case Action::PrecompileJobClass: 576 T = new tools::gcc::Precompile(*this); break; 577 case Action::AnalyzeJobClass: 578 T = new tools::Clang(*this); break; 579 case Action::CompileJobClass: 580 T = new tools::gcc::Compile(*this); break; 581 case Action::AssembleJobClass: 582 T = new tools::gcc::Assemble(*this); break; 583 case Action::LinkJobClass: 584 T = new tools::gcc::Link(*this); break; 585 586 // This is a bit ungeneric, but the only platform using a driver 587 // driver is Darwin. 588 case Action::LipoJobClass: 589 T = new tools::darwin::Lipo(*this); break; 590 } 591 } 592 593 return *T; 594} 595 596bool Generic_GCC::IsMathErrnoDefault() const { 597 return true; 598} 599 600bool Generic_GCC::IsUnwindTablesDefault() const { 601 // FIXME: Gross; we should probably have some separate target 602 // definition, possibly even reusing the one in clang. 603 return getArchName() == "x86_64"; 604} 605 606const char *Generic_GCC::GetDefaultRelocationModel() const { 607 return "static"; 608} 609 610const char *Generic_GCC::GetForcedPicModel() const { 611 return 0; 612} 613 614DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args, 615 const char *BoundArch) const { 616 return new DerivedArgList(Args, true); 617} 618 619/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. 620 621OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple) 622 : Generic_GCC(Host, Triple) { 623 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib"); 624 getFilePaths().push_back("/usr/lib"); 625} 626 627Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const { 628 Action::ActionClass Key; 629 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 630 Key = Action::AnalyzeJobClass; 631 else 632 Key = JA.getKind(); 633 634 Tool *&T = Tools[Key]; 635 if (!T) { 636 switch (Key) { 637 case Action::AssembleJobClass: 638 T = new tools::openbsd::Assemble(*this); break; 639 case Action::LinkJobClass: 640 T = new tools::openbsd::Link(*this); break; 641 default: 642 T = &Generic_GCC::SelectTool(C, JA); 643 } 644 } 645 646 return *T; 647} 648 649/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. 650 651FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32) 652 : Generic_GCC(Host, Triple) { 653 if (Lib32) { 654 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib32"); 655 getFilePaths().push_back("/usr/lib32"); 656 } else { 657 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib"); 658 getFilePaths().push_back("/usr/lib"); 659 } 660} 661 662Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { 663 Action::ActionClass Key; 664 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 665 Key = Action::AnalyzeJobClass; 666 else 667 Key = JA.getKind(); 668 669 Tool *&T = Tools[Key]; 670 if (!T) { 671 switch (Key) { 672 case Action::AssembleJobClass: 673 T = new tools::freebsd::Assemble(*this); break; 674 case Action::LinkJobClass: 675 T = new tools::freebsd::Link(*this); break; 676 default: 677 T = &Generic_GCC::SelectTool(C, JA); 678 } 679 } 680 681 return *T; 682} 683 684/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly. 685 686AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple) 687 : Generic_GCC(Host, Triple) { 688 689 // Path mangling to find libexec 690 std::string Path(getHost().getDriver().Dir); 691 692 Path += "/../libexec"; 693 getProgramPaths().push_back(Path); 694 getProgramPaths().push_back(getHost().getDriver().Dir); 695 696 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib"); 697 getFilePaths().push_back("/usr/lib"); 698 getFilePaths().push_back("/usr/sfw/lib"); 699 getFilePaths().push_back("/opt/gcc4/lib"); 700 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4"); 701 702} 703 704Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const { 705 Action::ActionClass Key; 706 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 707 Key = Action::AnalyzeJobClass; 708 else 709 Key = JA.getKind(); 710 711 Tool *&T = Tools[Key]; 712 if (!T) { 713 switch (Key) { 714 case Action::AssembleJobClass: 715 T = new tools::auroraux::Assemble(*this); break; 716 case Action::LinkJobClass: 717 T = new tools::auroraux::Link(*this); break; 718 default: 719 T = &Generic_GCC::SelectTool(C, JA); 720 } 721 } 722 723 return *T; 724} 725 726 727/// Linux toolchain (very bare-bones at the moment). 728 729Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple) 730 : Generic_GCC(Host, Triple) { 731 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib/clang/1.0/"); 732 getFilePaths().push_back("/lib/"); 733 getFilePaths().push_back("/usr/lib/"); 734 735 // Depending on the Linux distribution, any combination of lib{,32,64} is 736 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems, 737 // openSUSE uses lib and lib64 for the same purpose. 738 getFilePaths().push_back("/lib32/"); 739 getFilePaths().push_back("/usr/lib32/"); 740 getFilePaths().push_back("/lib64/"); 741 getFilePaths().push_back("/usr/lib64/"); 742 743 // FIXME: Figure out some way to get gcc's libdir 744 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need 745 // crtbegin.o/crtend.o/etc., and want static versions of various 746 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably 747 // get away with using shared versions in /usr/lib, though. 748 // We could fall back to the approach we used for includes (a massive 749 // list), but that's messy at best. 750} 751 752/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. 753 754DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple) 755 : Generic_GCC(Host, Triple) { 756 757 // Path mangling to find libexec 758 std::string Path(getHost().getDriver().Dir); 759 760 Path += "/../libexec"; 761 getProgramPaths().push_back(Path); 762 getProgramPaths().push_back(getHost().getDriver().Dir); 763 764 getFilePaths().push_back(getHost().getDriver().Dir + "/../lib"); 765 getFilePaths().push_back("/usr/lib"); 766 getFilePaths().push_back("/usr/lib/gcc41"); 767} 768 769Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const { 770 Action::ActionClass Key; 771 if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 772 Key = Action::AnalyzeJobClass; 773 else 774 Key = JA.getKind(); 775 776 Tool *&T = Tools[Key]; 777 if (!T) { 778 switch (Key) { 779 case Action::AssembleJobClass: 780 T = new tools::dragonfly::Assemble(*this); break; 781 case Action::LinkJobClass: 782 T = new tools::dragonfly::Link(*this); break; 783 default: 784 T = &Generic_GCC::SelectTool(C, JA); 785 } 786 } 787 788 return *T; 789} 790