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