ToolChains.cpp revision 202379
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 = 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 = 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 = 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 = getDriver().Dir; 122 Path += "/../libexec"; 123 getProgramPaths().push_back(Path); 124 125 getProgramPaths().push_back(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 (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 Args.hasFlag(options::OPT_fexceptions, 207 options::OPT_fno_exceptions) || 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 = 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(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 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 = 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 = 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 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 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_unreachable("invalid Darwin arch"); 514 } 515 516 return DAL; 517} 518 519bool Darwin::IsUnwindTablesDefault() const { 520 // FIXME: Gross; we should probably have some separate target 521 // definition, possibly even reusing the one in clang. 522 return getArchName() == "x86_64"; 523} 524 525bool Darwin::UseDwarfDebugFlags() const { 526 if (const char *S = ::getenv("RC_DEBUG_OPTIONS")) 527 return S[0] != '\0'; 528 return false; 529} 530 531const char *Darwin::GetDefaultRelocationModel() const { 532 return "pic"; 533} 534 535const char *Darwin::GetForcedPicModel() const { 536 if (getArchName() == "x86_64") 537 return "pic"; 538 return 0; 539} 540 541/// Generic_GCC - A tool chain using the 'gcc' command to perform 542/// all subcommands; this relies on gcc translating the majority of 543/// command line options. 544 545Generic_GCC::Generic_GCC(const HostInfo &Host, const llvm::Triple& Triple) 546 : ToolChain(Host, Triple) { 547 std::string Path(getDriver().Dir); 548 Path += "/../libexec"; 549 getProgramPaths().push_back(Path); 550 551 getProgramPaths().push_back(getDriver().Dir); 552} 553 554Generic_GCC::~Generic_GCC() { 555 // Free tool implementations. 556 for (llvm::DenseMap<unsigned, Tool*>::iterator 557 it = Tools.begin(), ie = Tools.end(); it != ie; ++it) 558 delete it->second; 559} 560 561Tool &Generic_GCC::SelectTool(const Compilation &C, 562 const JobAction &JA) const { 563 Action::ActionClass Key; 564 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 565 Key = Action::AnalyzeJobClass; 566 else 567 Key = JA.getKind(); 568 569 Tool *&T = Tools[Key]; 570 if (!T) { 571 switch (Key) { 572 case Action::InputClass: 573 case Action::BindArchClass: 574 assert(0 && "Invalid tool kind."); 575 case Action::PreprocessJobClass: 576 T = new tools::gcc::Preprocess(*this); break; 577 case Action::PrecompileJobClass: 578 T = new tools::gcc::Precompile(*this); break; 579 case Action::AnalyzeJobClass: 580 T = new tools::Clang(*this); break; 581 case Action::CompileJobClass: 582 T = new tools::gcc::Compile(*this); break; 583 case Action::AssembleJobClass: 584 T = new tools::gcc::Assemble(*this); break; 585 case Action::LinkJobClass: 586 T = new tools::gcc::Link(*this); break; 587 588 // This is a bit ungeneric, but the only platform using a driver 589 // driver is Darwin. 590 case Action::LipoJobClass: 591 T = new tools::darwin::Lipo(*this); break; 592 } 593 } 594 595 return *T; 596} 597 598bool Generic_GCC::IsUnwindTablesDefault() const { 599 // FIXME: Gross; we should probably have some separate target 600 // definition, possibly even reusing the one in clang. 601 return getArchName() == "x86_64"; 602} 603 604const char *Generic_GCC::GetDefaultRelocationModel() const { 605 return "static"; 606} 607 608const char *Generic_GCC::GetForcedPicModel() const { 609 return 0; 610} 611 612DerivedArgList *Generic_GCC::TranslateArgs(InputArgList &Args, 613 const char *BoundArch) const { 614 return new DerivedArgList(Args, true); 615} 616 617/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly. 618 619OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple) 620 : Generic_GCC(Host, Triple) { 621 getFilePaths().push_back(getDriver().Dir + "/../lib"); 622 getFilePaths().push_back("/usr/lib"); 623} 624 625Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const { 626 Action::ActionClass Key; 627 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 628 Key = Action::AnalyzeJobClass; 629 else 630 Key = JA.getKind(); 631 632 Tool *&T = Tools[Key]; 633 if (!T) { 634 switch (Key) { 635 case Action::AssembleJobClass: 636 T = new tools::openbsd::Assemble(*this); break; 637 case Action::LinkJobClass: 638 T = new tools::openbsd::Link(*this); break; 639 default: 640 T = &Generic_GCC::SelectTool(C, JA); 641 } 642 } 643 644 return *T; 645} 646 647/// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. 648 649FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32) 650 : Generic_GCC(Host, Triple) { 651 if (Lib32) { 652 getFilePaths().push_back(getDriver().Dir + "/../lib32"); 653 getFilePaths().push_back("/usr/lib32"); 654 } else { 655 getFilePaths().push_back(getDriver().Dir + "/../lib"); 656 getFilePaths().push_back("/usr/lib"); 657 } 658} 659 660Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { 661 Action::ActionClass Key; 662 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 663 Key = Action::AnalyzeJobClass; 664 else 665 Key = JA.getKind(); 666 667 Tool *&T = Tools[Key]; 668 if (!T) { 669 switch (Key) { 670 case Action::AssembleJobClass: 671 T = new tools::freebsd::Assemble(*this); break; 672 case Action::LinkJobClass: 673 T = new tools::freebsd::Link(*this); break; 674 default: 675 T = &Generic_GCC::SelectTool(C, JA); 676 } 677 } 678 679 return *T; 680} 681 682/// AuroraUX - AuroraUX tool chain which can call as(1) and ld(1) directly. 683 684AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple) 685 : Generic_GCC(Host, Triple) { 686 687 // Path mangling to find libexec 688 std::string Path(getDriver().Dir); 689 690 Path += "/../libexec"; 691 getProgramPaths().push_back(Path); 692 getProgramPaths().push_back(getDriver().Dir); 693 694 getFilePaths().push_back(getDriver().Dir + "/../lib"); 695 getFilePaths().push_back("/usr/lib"); 696 getFilePaths().push_back("/usr/sfw/lib"); 697 getFilePaths().push_back("/opt/gcc4/lib"); 698 getFilePaths().push_back("/opt/gcc4/lib/gcc/i386-pc-solaris2.11/4.2.4"); 699 700} 701 702Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const { 703 Action::ActionClass Key; 704 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 705 Key = Action::AnalyzeJobClass; 706 else 707 Key = JA.getKind(); 708 709 Tool *&T = Tools[Key]; 710 if (!T) { 711 switch (Key) { 712 case Action::AssembleJobClass: 713 T = new tools::auroraux::Assemble(*this); break; 714 case Action::LinkJobClass: 715 T = new tools::auroraux::Link(*this); break; 716 default: 717 T = &Generic_GCC::SelectTool(C, JA); 718 } 719 } 720 721 return *T; 722} 723 724 725/// Linux toolchain (very bare-bones at the moment). 726 727Linux::Linux(const HostInfo &Host, const llvm::Triple& Triple) 728 : Generic_GCC(Host, Triple) { 729 getFilePaths().push_back(getDriver().Dir + "/../lib/clang/1.0/"); 730 getFilePaths().push_back("/lib/"); 731 getFilePaths().push_back("/usr/lib/"); 732 733 // Depending on the Linux distribution, any combination of lib{,32,64} is 734 // possible. E.g. Debian uses lib and lib32 for mixed i386/x86-64 systems, 735 // openSUSE uses lib and lib64 for the same purpose. 736 getFilePaths().push_back("/lib32/"); 737 getFilePaths().push_back("/usr/lib32/"); 738 getFilePaths().push_back("/lib64/"); 739 getFilePaths().push_back("/usr/lib64/"); 740 741 // FIXME: Figure out some way to get gcc's libdir 742 // (e.g. /usr/lib/gcc/i486-linux-gnu/4.3/ for Ubuntu 32-bit); we need 743 // crtbegin.o/crtend.o/etc., and want static versions of various 744 // libraries. If we had our own crtbegin.o/crtend.o/etc, we could probably 745 // get away with using shared versions in /usr/lib, though. 746 // We could fall back to the approach we used for includes (a massive 747 // list), but that's messy at best. 748} 749 750/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. 751 752DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple) 753 : Generic_GCC(Host, Triple) { 754 755 // Path mangling to find libexec 756 std::string Path(getDriver().Dir); 757 758 Path += "/../libexec"; 759 getProgramPaths().push_back(Path); 760 getProgramPaths().push_back(getDriver().Dir); 761 762 getFilePaths().push_back(getDriver().Dir + "/../lib"); 763 getFilePaths().push_back("/usr/lib"); 764 getFilePaths().push_back("/usr/lib/gcc41"); 765} 766 767Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const { 768 Action::ActionClass Key; 769 if (getDriver().ShouldUseClangCompiler(C, JA, getTriple())) 770 Key = Action::AnalyzeJobClass; 771 else 772 Key = JA.getKind(); 773 774 Tool *&T = Tools[Key]; 775 if (!T) { 776 switch (Key) { 777 case Action::AssembleJobClass: 778 T = new tools::dragonfly::Assemble(*this); break; 779 case Action::LinkJobClass: 780 T = new tools::dragonfly::Link(*this); break; 781 default: 782 T = &Generic_GCC::SelectTool(C, JA); 783 } 784 } 785 786 return *T; 787} 788