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