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