10b57cec5SDimitry Andric //===--- NaCl.cpp - Native Client ToolChain Implementations -----*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #include "NaCl.h" 100b57cec5SDimitry Andric #include "CommonArgs.h" 110b57cec5SDimitry Andric #include "clang/Driver/Compilation.h" 120b57cec5SDimitry Andric #include "clang/Driver/Driver.h" 130b57cec5SDimitry Andric #include "clang/Driver/DriverDiagnostic.h" 14fe6060f1SDimitry Andric #include "clang/Driver/InputInfo.h" 150b57cec5SDimitry Andric #include "clang/Driver/Options.h" 160b57cec5SDimitry Andric #include "llvm/Option/ArgList.h" 170b57cec5SDimitry Andric #include "llvm/Support/Path.h" 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric using namespace clang::driver; 200b57cec5SDimitry Andric using namespace clang::driver::tools; 210b57cec5SDimitry Andric using namespace clang::driver::toolchains; 220b57cec5SDimitry Andric using namespace clang; 230b57cec5SDimitry Andric using namespace llvm::opt; 240b57cec5SDimitry Andric 250b57cec5SDimitry Andric // NaCl ARM assembly (inline or standalone) can be written with a set of macros 260b57cec5SDimitry Andric // for the various SFI requirements like register masking. The assembly tool 270b57cec5SDimitry Andric // inserts the file containing the macros as an input into all the assembly 280b57cec5SDimitry Andric // jobs. 290b57cec5SDimitry Andric void nacltools::AssemblerARM::ConstructJob(Compilation &C, const JobAction &JA, 300b57cec5SDimitry Andric const InputInfo &Output, 310b57cec5SDimitry Andric const InputInfoList &Inputs, 320b57cec5SDimitry Andric const ArgList &Args, 330b57cec5SDimitry Andric const char *LinkingOutput) const { 34*5f757f3fSDimitry Andric const auto &ToolChain = static_cast<const NaClToolChain &>(getToolChain()); 350b57cec5SDimitry Andric InputInfo NaClMacros(types::TY_PP_Asm, ToolChain.GetNaClArmMacrosPath(), 360b57cec5SDimitry Andric "nacl-arm-macros.s"); 370b57cec5SDimitry Andric InputInfoList NewInputs; 380b57cec5SDimitry Andric NewInputs.push_back(NaClMacros); 390b57cec5SDimitry Andric NewInputs.append(Inputs.begin(), Inputs.end()); 400b57cec5SDimitry Andric gnutools::Assembler::ConstructJob(C, JA, Output, NewInputs, Args, 410b57cec5SDimitry Andric LinkingOutput); 420b57cec5SDimitry Andric } 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric // This is quite similar to gnutools::Linker::ConstructJob with changes that 450b57cec5SDimitry Andric // we use static by default, do not yet support sanitizers or LTO, and a few 460b57cec5SDimitry Andric // others. Eventually we can support more of that and hopefully migrate back 470b57cec5SDimitry Andric // to gnutools::Linker. 480b57cec5SDimitry Andric void nacltools::Linker::ConstructJob(Compilation &C, const JobAction &JA, 490b57cec5SDimitry Andric const InputInfo &Output, 500b57cec5SDimitry Andric const InputInfoList &Inputs, 510b57cec5SDimitry Andric const ArgList &Args, 520b57cec5SDimitry Andric const char *LinkingOutput) const { 530b57cec5SDimitry Andric 54*5f757f3fSDimitry Andric const auto &ToolChain = static_cast<const NaClToolChain &>(getToolChain()); 550b57cec5SDimitry Andric const Driver &D = ToolChain.getDriver(); 560b57cec5SDimitry Andric const llvm::Triple::ArchType Arch = ToolChain.getArch(); 570b57cec5SDimitry Andric const bool IsStatic = 580b57cec5SDimitry Andric !Args.hasArg(options::OPT_dynamic) && !Args.hasArg(options::OPT_shared); 590b57cec5SDimitry Andric 600b57cec5SDimitry Andric ArgStringList CmdArgs; 610b57cec5SDimitry Andric 620b57cec5SDimitry Andric // Silence warning for "clang -g foo.o -o foo" 630b57cec5SDimitry Andric Args.ClaimAllArgs(options::OPT_g_Group); 640b57cec5SDimitry Andric // and "clang -emit-llvm foo.o -o foo" 650b57cec5SDimitry Andric Args.ClaimAllArgs(options::OPT_emit_llvm); 660b57cec5SDimitry Andric // and for "clang -w foo.o -o foo". Other warning options are already 670b57cec5SDimitry Andric // handled somewhere else. 680b57cec5SDimitry Andric Args.ClaimAllArgs(options::OPT_w); 690b57cec5SDimitry Andric 700b57cec5SDimitry Andric if (!D.SysRoot.empty()) 710b57cec5SDimitry Andric CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot)); 720b57cec5SDimitry Andric 730b57cec5SDimitry Andric if (Args.hasArg(options::OPT_rdynamic)) 740b57cec5SDimitry Andric CmdArgs.push_back("-export-dynamic"); 750b57cec5SDimitry Andric 760b57cec5SDimitry Andric if (Args.hasArg(options::OPT_s)) 770b57cec5SDimitry Andric CmdArgs.push_back("-s"); 780b57cec5SDimitry Andric 790b57cec5SDimitry Andric // NaClToolChain doesn't have ExtraOpts like Linux; the only relevant flag 800b57cec5SDimitry Andric // from there is --build-id, which we do want. 810b57cec5SDimitry Andric CmdArgs.push_back("--build-id"); 820b57cec5SDimitry Andric 830b57cec5SDimitry Andric if (!IsStatic) 840b57cec5SDimitry Andric CmdArgs.push_back("--eh-frame-hdr"); 850b57cec5SDimitry Andric 860b57cec5SDimitry Andric CmdArgs.push_back("-m"); 870b57cec5SDimitry Andric if (Arch == llvm::Triple::x86) 880b57cec5SDimitry Andric CmdArgs.push_back("elf_i386_nacl"); 890b57cec5SDimitry Andric else if (Arch == llvm::Triple::arm) 900b57cec5SDimitry Andric CmdArgs.push_back("armelf_nacl"); 910b57cec5SDimitry Andric else if (Arch == llvm::Triple::x86_64) 920b57cec5SDimitry Andric CmdArgs.push_back("elf_x86_64_nacl"); 930b57cec5SDimitry Andric else if (Arch == llvm::Triple::mipsel) 940b57cec5SDimitry Andric CmdArgs.push_back("mipselelf_nacl"); 950b57cec5SDimitry Andric else 960b57cec5SDimitry Andric D.Diag(diag::err_target_unsupported_arch) << ToolChain.getArchName() 970b57cec5SDimitry Andric << "Native Client"; 980b57cec5SDimitry Andric 990b57cec5SDimitry Andric if (IsStatic) 1000b57cec5SDimitry Andric CmdArgs.push_back("-static"); 1010b57cec5SDimitry Andric else if (Args.hasArg(options::OPT_shared)) 1020b57cec5SDimitry Andric CmdArgs.push_back("-shared"); 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andric CmdArgs.push_back("-o"); 1050b57cec5SDimitry Andric CmdArgs.push_back(Output.getFilename()); 1060b57cec5SDimitry Andric if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) { 1070b57cec5SDimitry Andric if (!Args.hasArg(options::OPT_shared)) 1080b57cec5SDimitry Andric CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o"))); 1090b57cec5SDimitry Andric CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o"))); 1100b57cec5SDimitry Andric 1110b57cec5SDimitry Andric const char *crtbegin; 1120b57cec5SDimitry Andric if (IsStatic) 1130b57cec5SDimitry Andric crtbegin = "crtbeginT.o"; 1140b57cec5SDimitry Andric else if (Args.hasArg(options::OPT_shared)) 1150b57cec5SDimitry Andric crtbegin = "crtbeginS.o"; 1160b57cec5SDimitry Andric else 1170b57cec5SDimitry Andric crtbegin = "crtbegin.o"; 1180b57cec5SDimitry Andric CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin))); 1190b57cec5SDimitry Andric } 1200b57cec5SDimitry Andric 121*5f757f3fSDimitry Andric Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u}); 1220b57cec5SDimitry Andric 1230b57cec5SDimitry Andric ToolChain.AddFilePathLibArgs(Args, CmdArgs); 1240b57cec5SDimitry Andric 1250b57cec5SDimitry Andric if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle)) 1260b57cec5SDimitry Andric CmdArgs.push_back("--no-demangle"); 1270b57cec5SDimitry Andric 1280b57cec5SDimitry Andric AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); 1290b57cec5SDimitry Andric 1300b57cec5SDimitry Andric if (D.CCCIsCXX() && 1310b57cec5SDimitry Andric !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { 1320b57cec5SDimitry Andric if (ToolChain.ShouldLinkCXXStdlib(Args)) { 1330b57cec5SDimitry Andric bool OnlyLibstdcxxStatic = 1340b57cec5SDimitry Andric Args.hasArg(options::OPT_static_libstdcxx) && !IsStatic; 1350b57cec5SDimitry Andric if (OnlyLibstdcxxStatic) 1360b57cec5SDimitry Andric CmdArgs.push_back("-Bstatic"); 1370b57cec5SDimitry Andric ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); 1380b57cec5SDimitry Andric if (OnlyLibstdcxxStatic) 1390b57cec5SDimitry Andric CmdArgs.push_back("-Bdynamic"); 1400b57cec5SDimitry Andric } 1410b57cec5SDimitry Andric CmdArgs.push_back("-lm"); 1420b57cec5SDimitry Andric } 1430b57cec5SDimitry Andric 1440b57cec5SDimitry Andric if (!Args.hasArg(options::OPT_nostdlib)) { 1450b57cec5SDimitry Andric if (!Args.hasArg(options::OPT_nodefaultlibs)) { 1460b57cec5SDimitry Andric // Always use groups, since it has no effect on dynamic libraries. 1470b57cec5SDimitry Andric CmdArgs.push_back("--start-group"); 1480b57cec5SDimitry Andric CmdArgs.push_back("-lc"); 1490b57cec5SDimitry Andric // NaCl's libc++ currently requires libpthread, so just always include it 1500b57cec5SDimitry Andric // in the group for C++. 1510b57cec5SDimitry Andric if (Args.hasArg(options::OPT_pthread) || 1520b57cec5SDimitry Andric Args.hasArg(options::OPT_pthreads) || D.CCCIsCXX()) { 1530b57cec5SDimitry Andric // Gold, used by Mips, handles nested groups differently than ld, and 1540b57cec5SDimitry Andric // without '-lnacl' it prefers symbols from libpthread.a over libnacl.a, 1550b57cec5SDimitry Andric // which is not a desired behaviour here. 1560b57cec5SDimitry Andric // See https://sourceware.org/ml/binutils/2015-03/msg00034.html 1570b57cec5SDimitry Andric if (getToolChain().getArch() == llvm::Triple::mipsel) 1580b57cec5SDimitry Andric CmdArgs.push_back("-lnacl"); 1590b57cec5SDimitry Andric 1600b57cec5SDimitry Andric CmdArgs.push_back("-lpthread"); 1610b57cec5SDimitry Andric } 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andric CmdArgs.push_back("-lgcc"); 1640b57cec5SDimitry Andric CmdArgs.push_back("--as-needed"); 1650b57cec5SDimitry Andric if (IsStatic) 1660b57cec5SDimitry Andric CmdArgs.push_back("-lgcc_eh"); 1670b57cec5SDimitry Andric else 1680b57cec5SDimitry Andric CmdArgs.push_back("-lgcc_s"); 1690b57cec5SDimitry Andric CmdArgs.push_back("--no-as-needed"); 1700b57cec5SDimitry Andric 1710b57cec5SDimitry Andric // Mips needs to create and use pnacl_legacy library that contains 1720b57cec5SDimitry Andric // definitions from bitcode/pnaclmm.c and definitions for 1730b57cec5SDimitry Andric // __nacl_tp_tls_offset() and __nacl_tp_tdb_offset(). 1740b57cec5SDimitry Andric if (getToolChain().getArch() == llvm::Triple::mipsel) 1750b57cec5SDimitry Andric CmdArgs.push_back("-lpnacl_legacy"); 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andric CmdArgs.push_back("--end-group"); 1780b57cec5SDimitry Andric } 1790b57cec5SDimitry Andric 1800b57cec5SDimitry Andric if (!Args.hasArg(options::OPT_nostartfiles)) { 1810b57cec5SDimitry Andric const char *crtend; 1820b57cec5SDimitry Andric if (Args.hasArg(options::OPT_shared)) 1830b57cec5SDimitry Andric crtend = "crtendS.o"; 1840b57cec5SDimitry Andric else 1850b57cec5SDimitry Andric crtend = "crtend.o"; 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtend))); 1880b57cec5SDimitry Andric CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o"))); 1890b57cec5SDimitry Andric } 1900b57cec5SDimitry Andric } 1910b57cec5SDimitry Andric 1920b57cec5SDimitry Andric const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); 193e8d8bef9SDimitry Andric C.addCommand(std::make_unique<Command>(JA, *this, 194e8d8bef9SDimitry Andric ResponseFileSupport::AtFileCurCP(), 195e8d8bef9SDimitry Andric Exec, CmdArgs, Inputs, Output)); 1960b57cec5SDimitry Andric } 1970b57cec5SDimitry Andric 1980b57cec5SDimitry Andric /// NaCl Toolchain 1990b57cec5SDimitry Andric NaClToolChain::NaClToolChain(const Driver &D, const llvm::Triple &Triple, 2000b57cec5SDimitry Andric const ArgList &Args) 2010b57cec5SDimitry Andric : Generic_ELF(D, Triple, Args) { 2020b57cec5SDimitry Andric 2030b57cec5SDimitry Andric // Remove paths added by Generic_GCC. NaCl Toolchain cannot use the 2040b57cec5SDimitry Andric // default paths, and must instead only use the paths provided 2050b57cec5SDimitry Andric // with this toolchain based on architecture. 2060b57cec5SDimitry Andric path_list &file_paths = getFilePaths(); 2070b57cec5SDimitry Andric path_list &prog_paths = getProgramPaths(); 2080b57cec5SDimitry Andric 2090b57cec5SDimitry Andric file_paths.clear(); 2100b57cec5SDimitry Andric prog_paths.clear(); 2110b57cec5SDimitry Andric 2120b57cec5SDimitry Andric // Path for library files (libc.a, ...) 2130b57cec5SDimitry Andric std::string FilePath(getDriver().Dir + "/../"); 2140b57cec5SDimitry Andric 2150b57cec5SDimitry Andric // Path for tools (clang, ld, etc..) 2160b57cec5SDimitry Andric std::string ProgPath(getDriver().Dir + "/../"); 2170b57cec5SDimitry Andric 2180b57cec5SDimitry Andric // Path for toolchain libraries (libgcc.a, ...) 2190b57cec5SDimitry Andric std::string ToolPath(getDriver().ResourceDir + "/lib/"); 2200b57cec5SDimitry Andric 2210b57cec5SDimitry Andric switch (Triple.getArch()) { 2220b57cec5SDimitry Andric case llvm::Triple::x86: 2230b57cec5SDimitry Andric file_paths.push_back(FilePath + "x86_64-nacl/lib32"); 2240b57cec5SDimitry Andric file_paths.push_back(FilePath + "i686-nacl/usr/lib"); 2250b57cec5SDimitry Andric prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); 2260b57cec5SDimitry Andric file_paths.push_back(ToolPath + "i686-nacl"); 2270b57cec5SDimitry Andric break; 2280b57cec5SDimitry Andric case llvm::Triple::x86_64: 2290b57cec5SDimitry Andric file_paths.push_back(FilePath + "x86_64-nacl/lib"); 2300b57cec5SDimitry Andric file_paths.push_back(FilePath + "x86_64-nacl/usr/lib"); 2310b57cec5SDimitry Andric prog_paths.push_back(ProgPath + "x86_64-nacl/bin"); 2320b57cec5SDimitry Andric file_paths.push_back(ToolPath + "x86_64-nacl"); 2330b57cec5SDimitry Andric break; 2340b57cec5SDimitry Andric case llvm::Triple::arm: 2350b57cec5SDimitry Andric file_paths.push_back(FilePath + "arm-nacl/lib"); 2360b57cec5SDimitry Andric file_paths.push_back(FilePath + "arm-nacl/usr/lib"); 2370b57cec5SDimitry Andric prog_paths.push_back(ProgPath + "arm-nacl/bin"); 2380b57cec5SDimitry Andric file_paths.push_back(ToolPath + "arm-nacl"); 2390b57cec5SDimitry Andric break; 2400b57cec5SDimitry Andric case llvm::Triple::mipsel: 2410b57cec5SDimitry Andric file_paths.push_back(FilePath + "mipsel-nacl/lib"); 2420b57cec5SDimitry Andric file_paths.push_back(FilePath + "mipsel-nacl/usr/lib"); 2430b57cec5SDimitry Andric prog_paths.push_back(ProgPath + "bin"); 2440b57cec5SDimitry Andric file_paths.push_back(ToolPath + "mipsel-nacl"); 2450b57cec5SDimitry Andric break; 2460b57cec5SDimitry Andric default: 2470b57cec5SDimitry Andric break; 2480b57cec5SDimitry Andric } 2490b57cec5SDimitry Andric 2500b57cec5SDimitry Andric NaClArmMacrosPath = GetFilePath("nacl-arm-macros.s"); 2510b57cec5SDimitry Andric } 2520b57cec5SDimitry Andric 2530b57cec5SDimitry Andric void NaClToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, 2540b57cec5SDimitry Andric ArgStringList &CC1Args) const { 2550b57cec5SDimitry Andric const Driver &D = getDriver(); 2560b57cec5SDimitry Andric if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc)) 2570b57cec5SDimitry Andric return; 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andric if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) { 2600b57cec5SDimitry Andric SmallString<128> P(D.ResourceDir); 2610b57cec5SDimitry Andric llvm::sys::path::append(P, "include"); 2620b57cec5SDimitry Andric addSystemInclude(DriverArgs, CC1Args, P.str()); 2630b57cec5SDimitry Andric } 2640b57cec5SDimitry Andric 2650b57cec5SDimitry Andric if (DriverArgs.hasArg(options::OPT_nostdlibinc)) 2660b57cec5SDimitry Andric return; 2670b57cec5SDimitry Andric 2680b57cec5SDimitry Andric SmallString<128> P(D.Dir + "/../"); 2690b57cec5SDimitry Andric switch (getTriple().getArch()) { 2700b57cec5SDimitry Andric case llvm::Triple::x86: 2710b57cec5SDimitry Andric // x86 is special because multilib style uses x86_64-nacl/include for libc 2720b57cec5SDimitry Andric // headers but the SDK wants i686-nacl/usr/include. The other architectures 2730b57cec5SDimitry Andric // have the same substring. 2740b57cec5SDimitry Andric llvm::sys::path::append(P, "i686-nacl/usr/include"); 2750b57cec5SDimitry Andric addSystemInclude(DriverArgs, CC1Args, P.str()); 2760b57cec5SDimitry Andric llvm::sys::path::remove_filename(P); 2770b57cec5SDimitry Andric llvm::sys::path::remove_filename(P); 2780b57cec5SDimitry Andric llvm::sys::path::remove_filename(P); 2790b57cec5SDimitry Andric llvm::sys::path::append(P, "x86_64-nacl/include"); 2800b57cec5SDimitry Andric addSystemInclude(DriverArgs, CC1Args, P.str()); 2810b57cec5SDimitry Andric return; 2820b57cec5SDimitry Andric case llvm::Triple::arm: 2830b57cec5SDimitry Andric llvm::sys::path::append(P, "arm-nacl/usr/include"); 2840b57cec5SDimitry Andric break; 2850b57cec5SDimitry Andric case llvm::Triple::x86_64: 2860b57cec5SDimitry Andric llvm::sys::path::append(P, "x86_64-nacl/usr/include"); 2870b57cec5SDimitry Andric break; 2880b57cec5SDimitry Andric case llvm::Triple::mipsel: 2890b57cec5SDimitry Andric llvm::sys::path::append(P, "mipsel-nacl/usr/include"); 2900b57cec5SDimitry Andric break; 2910b57cec5SDimitry Andric default: 2920b57cec5SDimitry Andric return; 2930b57cec5SDimitry Andric } 2940b57cec5SDimitry Andric 2950b57cec5SDimitry Andric addSystemInclude(DriverArgs, CC1Args, P.str()); 2960b57cec5SDimitry Andric llvm::sys::path::remove_filename(P); 2970b57cec5SDimitry Andric llvm::sys::path::remove_filename(P); 2980b57cec5SDimitry Andric llvm::sys::path::append(P, "include"); 2990b57cec5SDimitry Andric addSystemInclude(DriverArgs, CC1Args, P.str()); 3000b57cec5SDimitry Andric } 3010b57cec5SDimitry Andric 3020b57cec5SDimitry Andric void NaClToolChain::AddCXXStdlibLibArgs(const ArgList &Args, 3030b57cec5SDimitry Andric ArgStringList &CmdArgs) const { 3040b57cec5SDimitry Andric // Check for -stdlib= flags. We only support libc++ but this consumes the arg 3050b57cec5SDimitry Andric // if the value is libc++, and emits an error for other values. 3060b57cec5SDimitry Andric GetCXXStdlibType(Args); 3070b57cec5SDimitry Andric CmdArgs.push_back("-lc++"); 308fcaf7f86SDimitry Andric if (Args.hasArg(options::OPT_fexperimental_library)) 309fcaf7f86SDimitry Andric CmdArgs.push_back("-lc++experimental"); 3100b57cec5SDimitry Andric } 3110b57cec5SDimitry Andric 3120b57cec5SDimitry Andric void NaClToolChain::addLibCxxIncludePaths( 3130b57cec5SDimitry Andric const llvm::opt::ArgList &DriverArgs, 3140b57cec5SDimitry Andric llvm::opt::ArgStringList &CC1Args) const { 3150b57cec5SDimitry Andric const Driver &D = getDriver(); 3160b57cec5SDimitry Andric 3170b57cec5SDimitry Andric SmallString<128> P(D.Dir + "/../"); 3180b57cec5SDimitry Andric switch (getTriple().getArch()) { 3190b57cec5SDimitry Andric default: 3200b57cec5SDimitry Andric break; 3210b57cec5SDimitry Andric case llvm::Triple::arm: 3220b57cec5SDimitry Andric llvm::sys::path::append(P, "arm-nacl/include/c++/v1"); 3230b57cec5SDimitry Andric addSystemInclude(DriverArgs, CC1Args, P.str()); 3240b57cec5SDimitry Andric break; 3250b57cec5SDimitry Andric case llvm::Triple::x86: 3260b57cec5SDimitry Andric llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); 3270b57cec5SDimitry Andric addSystemInclude(DriverArgs, CC1Args, P.str()); 3280b57cec5SDimitry Andric break; 3290b57cec5SDimitry Andric case llvm::Triple::x86_64: 3300b57cec5SDimitry Andric llvm::sys::path::append(P, "x86_64-nacl/include/c++/v1"); 3310b57cec5SDimitry Andric addSystemInclude(DriverArgs, CC1Args, P.str()); 3320b57cec5SDimitry Andric break; 3330b57cec5SDimitry Andric case llvm::Triple::mipsel: 3340b57cec5SDimitry Andric llvm::sys::path::append(P, "mipsel-nacl/include/c++/v1"); 3350b57cec5SDimitry Andric addSystemInclude(DriverArgs, CC1Args, P.str()); 3360b57cec5SDimitry Andric break; 3370b57cec5SDimitry Andric } 3380b57cec5SDimitry Andric } 3390b57cec5SDimitry Andric 3400b57cec5SDimitry Andric ToolChain::CXXStdlibType 3410b57cec5SDimitry Andric NaClToolChain::GetCXXStdlibType(const ArgList &Args) const { 3420b57cec5SDimitry Andric if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { 3430b57cec5SDimitry Andric StringRef Value = A->getValue(); 3440b57cec5SDimitry Andric if (Value == "libc++") 3450b57cec5SDimitry Andric return ToolChain::CST_Libcxx; 3460b57cec5SDimitry Andric getDriver().Diag(clang::diag::err_drv_invalid_stdlib_name) 3470b57cec5SDimitry Andric << A->getAsString(Args); 3480b57cec5SDimitry Andric } 3490b57cec5SDimitry Andric 3500b57cec5SDimitry Andric return ToolChain::CST_Libcxx; 3510b57cec5SDimitry Andric } 3520b57cec5SDimitry Andric 3530b57cec5SDimitry Andric std::string 3540b57cec5SDimitry Andric NaClToolChain::ComputeEffectiveClangTriple(const ArgList &Args, 3550b57cec5SDimitry Andric types::ID InputType) const { 3560b57cec5SDimitry Andric llvm::Triple TheTriple(ComputeLLVMTriple(Args, InputType)); 3570b57cec5SDimitry Andric if (TheTriple.getArch() == llvm::Triple::arm && 3580b57cec5SDimitry Andric TheTriple.getEnvironment() == llvm::Triple::UnknownEnvironment) 3590b57cec5SDimitry Andric TheTriple.setEnvironment(llvm::Triple::GNUEABIHF); 3600b57cec5SDimitry Andric return TheTriple.getTriple(); 3610b57cec5SDimitry Andric } 3620b57cec5SDimitry Andric 3630b57cec5SDimitry Andric Tool *NaClToolChain::buildLinker() const { 3640b57cec5SDimitry Andric return new tools::nacltools::Linker(*this); 3650b57cec5SDimitry Andric } 3660b57cec5SDimitry Andric 3670b57cec5SDimitry Andric Tool *NaClToolChain::buildAssembler() const { 3680b57cec5SDimitry Andric if (getTriple().getArch() == llvm::Triple::arm) 3690b57cec5SDimitry Andric return new tools::nacltools::AssemblerARM(*this); 3700b57cec5SDimitry Andric return new tools::gnutools::Assembler(*this); 3710b57cec5SDimitry Andric } 372