xref: /freebsd/contrib/llvm-project/clang/lib/Driver/ToolChains/WebAssembly.cpp (revision 480093f4440d54b30b3025afeac24b48f2ba7a2e)
10b57cec5SDimitry Andric //===--- WebAssembly.cpp - WebAssembly ToolChain Implementation -*- 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 "WebAssembly.h"
100b57cec5SDimitry Andric #include "CommonArgs.h"
11*480093f4SDimitry Andric #include "clang/Basic/Version.h"
120b57cec5SDimitry Andric #include "clang/Config/config.h"
130b57cec5SDimitry Andric #include "clang/Driver/Compilation.h"
140b57cec5SDimitry Andric #include "clang/Driver/Driver.h"
150b57cec5SDimitry Andric #include "clang/Driver/DriverDiagnostic.h"
160b57cec5SDimitry Andric #include "clang/Driver/Options.h"
170b57cec5SDimitry Andric #include "llvm/Support/FileSystem.h"
180b57cec5SDimitry Andric #include "llvm/Support/Path.h"
190b57cec5SDimitry Andric #include "llvm/Option/ArgList.h"
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric using namespace clang::driver;
220b57cec5SDimitry Andric using namespace clang::driver::tools;
230b57cec5SDimitry Andric using namespace clang::driver::toolchains;
240b57cec5SDimitry Andric using namespace clang;
250b57cec5SDimitry Andric using namespace llvm::opt;
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric /// Following the conventions in https://wiki.debian.org/Multiarch/Tuples,
280b57cec5SDimitry Andric /// we remove the vendor field to form the multiarch triple.
290b57cec5SDimitry Andric static std::string getMultiarchTriple(const Driver &D,
300b57cec5SDimitry Andric                                       const llvm::Triple &TargetTriple,
310b57cec5SDimitry Andric                                       StringRef SysRoot) {
320b57cec5SDimitry Andric     return (TargetTriple.getArchName() + "-" +
330b57cec5SDimitry Andric             TargetTriple.getOSAndEnvironmentName()).str();
340b57cec5SDimitry Andric }
350b57cec5SDimitry Andric 
360b57cec5SDimitry Andric std::string wasm::Linker::getLinkerPath(const ArgList &Args) const {
370b57cec5SDimitry Andric   const ToolChain &ToolChain = getToolChain();
380b57cec5SDimitry Andric   if (const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
390b57cec5SDimitry Andric     StringRef UseLinker = A->getValue();
400b57cec5SDimitry Andric     if (!UseLinker.empty()) {
410b57cec5SDimitry Andric       if (llvm::sys::path::is_absolute(UseLinker) &&
420b57cec5SDimitry Andric           llvm::sys::fs::can_execute(UseLinker))
430b57cec5SDimitry Andric         return UseLinker;
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric       // Accept 'lld', and 'ld' as aliases for the default linker
460b57cec5SDimitry Andric       if (UseLinker != "lld" && UseLinker != "ld")
470b57cec5SDimitry Andric         ToolChain.getDriver().Diag(diag::err_drv_invalid_linker_name)
480b57cec5SDimitry Andric             << A->getAsString(Args);
490b57cec5SDimitry Andric     }
500b57cec5SDimitry Andric   }
510b57cec5SDimitry Andric 
520b57cec5SDimitry Andric   return ToolChain.GetProgramPath(ToolChain.getDefaultLinker());
530b57cec5SDimitry Andric }
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
560b57cec5SDimitry Andric                                 const InputInfo &Output,
570b57cec5SDimitry Andric                                 const InputInfoList &Inputs,
580b57cec5SDimitry Andric                                 const ArgList &Args,
590b57cec5SDimitry Andric                                 const char *LinkingOutput) const {
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric   const ToolChain &ToolChain = getToolChain();
620b57cec5SDimitry Andric   const char *Linker = Args.MakeArgString(getLinkerPath(Args));
630b57cec5SDimitry Andric   ArgStringList CmdArgs;
640b57cec5SDimitry Andric 
650b57cec5SDimitry Andric   if (Args.hasArg(options::OPT_s))
660b57cec5SDimitry Andric     CmdArgs.push_back("--strip-all");
670b57cec5SDimitry Andric 
680b57cec5SDimitry Andric   Args.AddAllArgs(CmdArgs, options::OPT_L);
690b57cec5SDimitry Andric   Args.AddAllArgs(CmdArgs, options::OPT_u);
700b57cec5SDimitry Andric   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
710b57cec5SDimitry Andric 
720b57cec5SDimitry Andric   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles))
730b57cec5SDimitry Andric     CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o")));
740b57cec5SDimitry Andric 
750b57cec5SDimitry Andric   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
760b57cec5SDimitry Andric 
770b57cec5SDimitry Andric   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
780b57cec5SDimitry Andric     if (ToolChain.ShouldLinkCXXStdlib(Args))
790b57cec5SDimitry Andric       ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
800b57cec5SDimitry Andric 
810b57cec5SDimitry Andric     if (Args.hasArg(options::OPT_pthread)) {
820b57cec5SDimitry Andric       CmdArgs.push_back("-lpthread");
830b57cec5SDimitry Andric       CmdArgs.push_back("--shared-memory");
840b57cec5SDimitry Andric     }
850b57cec5SDimitry Andric 
860b57cec5SDimitry Andric     CmdArgs.push_back("-lc");
870b57cec5SDimitry Andric     AddRunTimeLibs(ToolChain, ToolChain.getDriver(), CmdArgs, Args);
880b57cec5SDimitry Andric   }
890b57cec5SDimitry Andric 
900b57cec5SDimitry Andric   CmdArgs.push_back("-o");
910b57cec5SDimitry Andric   CmdArgs.push_back(Output.getFilename());
920b57cec5SDimitry Andric 
93a7dea167SDimitry Andric   C.addCommand(std::make_unique<Command>(JA, *this, Linker, CmdArgs, Inputs));
94*480093f4SDimitry Andric 
95*480093f4SDimitry Andric   // When optimizing, if wasm-opt is available, run it.
96*480093f4SDimitry Andric   if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
97*480093f4SDimitry Andric     auto WasmOptPath = getToolChain().GetProgramPath("wasm-opt");
98*480093f4SDimitry Andric     if (WasmOptPath != "wasm-opt") {
99*480093f4SDimitry Andric       StringRef OOpt = "s";
100*480093f4SDimitry Andric       if (A->getOption().matches(options::OPT_O4) ||
101*480093f4SDimitry Andric           A->getOption().matches(options::OPT_Ofast))
102*480093f4SDimitry Andric         OOpt = "4";
103*480093f4SDimitry Andric       else if (A->getOption().matches(options::OPT_O0))
104*480093f4SDimitry Andric         OOpt = "0";
105*480093f4SDimitry Andric       else if (A->getOption().matches(options::OPT_O))
106*480093f4SDimitry Andric         OOpt = A->getValue();
107*480093f4SDimitry Andric 
108*480093f4SDimitry Andric       if (OOpt != "0") {
109*480093f4SDimitry Andric         const char *WasmOpt = Args.MakeArgString(WasmOptPath);
110*480093f4SDimitry Andric         ArgStringList CmdArgs;
111*480093f4SDimitry Andric         CmdArgs.push_back(Output.getFilename());
112*480093f4SDimitry Andric         CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-O") + OOpt));
113*480093f4SDimitry Andric         CmdArgs.push_back("-o");
114*480093f4SDimitry Andric         CmdArgs.push_back(Output.getFilename());
115*480093f4SDimitry Andric         C.addCommand(std::make_unique<Command>(JA, *this, WasmOpt, CmdArgs, Inputs));
116*480093f4SDimitry Andric       }
117*480093f4SDimitry Andric     }
118*480093f4SDimitry Andric   }
119*480093f4SDimitry Andric }
120*480093f4SDimitry Andric 
121*480093f4SDimitry Andric /// Given a base library directory, append path components to form the
122*480093f4SDimitry Andric /// LTO directory.
123*480093f4SDimitry Andric static std::string AppendLTOLibDir(const std::string &Dir) {
124*480093f4SDimitry Andric     // The version allows the path to be keyed to the specific version of
125*480093f4SDimitry Andric     // LLVM in used, as the bitcode format is not stable.
126*480093f4SDimitry Andric     return Dir + "/llvm-lto/" LLVM_VERSION_STRING;
1270b57cec5SDimitry Andric }
1280b57cec5SDimitry Andric 
1290b57cec5SDimitry Andric WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple,
1300b57cec5SDimitry Andric                          const llvm::opt::ArgList &Args)
1310b57cec5SDimitry Andric     : ToolChain(D, Triple, Args) {
1320b57cec5SDimitry Andric 
1330b57cec5SDimitry Andric   assert(Triple.isArch32Bit() != Triple.isArch64Bit());
1340b57cec5SDimitry Andric 
1350b57cec5SDimitry Andric   getProgramPaths().push_back(getDriver().getInstalledDir());
1360b57cec5SDimitry Andric 
137*480093f4SDimitry Andric   auto SysRoot = getDriver().SysRoot;
1380b57cec5SDimitry Andric   if (getTriple().getOS() == llvm::Triple::UnknownOS) {
1390b57cec5SDimitry Andric     // Theoretically an "unknown" OS should mean no standard libraries, however
1400b57cec5SDimitry Andric     // it could also mean that a custom set of libraries is in use, so just add
1410b57cec5SDimitry Andric     // /lib to the search path. Disable multiarch in this case, to discourage
1420b57cec5SDimitry Andric     // paths containing "unknown" from acquiring meanings.
143*480093f4SDimitry Andric     getFilePaths().push_back(SysRoot + "/lib");
1440b57cec5SDimitry Andric   } else {
1450b57cec5SDimitry Andric     const std::string MultiarchTriple =
146*480093f4SDimitry Andric         getMultiarchTriple(getDriver(), Triple, SysRoot);
147*480093f4SDimitry Andric     if (D.isUsingLTO()) {
148*480093f4SDimitry Andric       // For LTO, enable use of lto-enabled sysroot libraries too, if available.
149*480093f4SDimitry Andric       // Note that the directory is keyed to the LLVM revision, as LLVM's
150*480093f4SDimitry Andric       // bitcode format is not stable.
151*480093f4SDimitry Andric       auto Dir = AppendLTOLibDir(SysRoot + "/lib/" + MultiarchTriple);
152*480093f4SDimitry Andric       getFilePaths().push_back(Dir);
153*480093f4SDimitry Andric     }
154*480093f4SDimitry Andric     getFilePaths().push_back(SysRoot + "/lib/" + MultiarchTriple);
1550b57cec5SDimitry Andric   }
1560b57cec5SDimitry Andric }
1570b57cec5SDimitry Andric 
1580b57cec5SDimitry Andric bool WebAssembly::IsMathErrnoDefault() const { return false; }
1590b57cec5SDimitry Andric 
1600b57cec5SDimitry Andric bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; }
1610b57cec5SDimitry Andric 
1620b57cec5SDimitry Andric bool WebAssembly::UseObjCMixedDispatch() const { return true; }
1630b57cec5SDimitry Andric 
1640b57cec5SDimitry Andric bool WebAssembly::isPICDefault() const { return false; }
1650b57cec5SDimitry Andric 
1660b57cec5SDimitry Andric bool WebAssembly::isPIEDefault() const { return false; }
1670b57cec5SDimitry Andric 
1680b57cec5SDimitry Andric bool WebAssembly::isPICDefaultForced() const { return false; }
1690b57cec5SDimitry Andric 
1700b57cec5SDimitry Andric bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; }
1710b57cec5SDimitry Andric 
1720b57cec5SDimitry Andric bool WebAssembly::hasBlocksRuntime() const { return false; }
1730b57cec5SDimitry Andric 
1740b57cec5SDimitry Andric // TODO: Support profiling.
1750b57cec5SDimitry Andric bool WebAssembly::SupportsProfiling() const { return false; }
1760b57cec5SDimitry Andric 
1770b57cec5SDimitry Andric bool WebAssembly::HasNativeLLVMSupport() const { return true; }
1780b57cec5SDimitry Andric 
1790b57cec5SDimitry Andric void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
1800b57cec5SDimitry Andric                                         ArgStringList &CC1Args,
1810b57cec5SDimitry Andric                                         Action::OffloadKind) const {
182*480093f4SDimitry Andric   if (!DriverArgs.hasFlag(clang::driver::options::OPT_fuse_init_array,
1830b57cec5SDimitry Andric                           options::OPT_fno_use_init_array, true))
184*480093f4SDimitry Andric     CC1Args.push_back("-fno-use-init-array");
1850b57cec5SDimitry Andric 
186a7dea167SDimitry Andric   // '-pthread' implies atomics, bulk-memory, mutable-globals, and sign-ext
1870b57cec5SDimitry Andric   if (DriverArgs.hasFlag(options::OPT_pthread, options::OPT_no_pthread,
1880b57cec5SDimitry Andric                          false)) {
1890b57cec5SDimitry Andric     if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
1900b57cec5SDimitry Andric                            false))
1910b57cec5SDimitry Andric       getDriver().Diag(diag::err_drv_argument_not_allowed_with)
1920b57cec5SDimitry Andric           << "-pthread"
1930b57cec5SDimitry Andric           << "-mno-atomics";
1940b57cec5SDimitry Andric     if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
1950b57cec5SDimitry Andric                            options::OPT_mbulk_memory, false))
1960b57cec5SDimitry Andric       getDriver().Diag(diag::err_drv_argument_not_allowed_with)
1970b57cec5SDimitry Andric           << "-pthread"
1980b57cec5SDimitry Andric           << "-mno-bulk-memory";
1990b57cec5SDimitry Andric     if (DriverArgs.hasFlag(options::OPT_mno_mutable_globals,
2000b57cec5SDimitry Andric                            options::OPT_mmutable_globals, false))
2010b57cec5SDimitry Andric       getDriver().Diag(diag::err_drv_argument_not_allowed_with)
2020b57cec5SDimitry Andric           << "-pthread"
2030b57cec5SDimitry Andric           << "-mno-mutable-globals";
204a7dea167SDimitry Andric     if (DriverArgs.hasFlag(options::OPT_mno_sign_ext, options::OPT_msign_ext,
205a7dea167SDimitry Andric                            false))
206a7dea167SDimitry Andric       getDriver().Diag(diag::err_drv_argument_not_allowed_with)
207a7dea167SDimitry Andric           << "-pthread"
208a7dea167SDimitry Andric           << "-mno-sign-ext";
2090b57cec5SDimitry Andric     CC1Args.push_back("-target-feature");
2100b57cec5SDimitry Andric     CC1Args.push_back("+atomics");
2110b57cec5SDimitry Andric     CC1Args.push_back("-target-feature");
2120b57cec5SDimitry Andric     CC1Args.push_back("+bulk-memory");
2130b57cec5SDimitry Andric     CC1Args.push_back("-target-feature");
2140b57cec5SDimitry Andric     CC1Args.push_back("+mutable-globals");
215a7dea167SDimitry Andric     CC1Args.push_back("-target-feature");
216a7dea167SDimitry Andric     CC1Args.push_back("+sign-ext");
217a7dea167SDimitry Andric   }
218a7dea167SDimitry Andric 
219a7dea167SDimitry Andric   if (DriverArgs.getLastArg(options::OPT_fwasm_exceptions)) {
220a7dea167SDimitry Andric     // '-fwasm-exceptions' is not compatible with '-mno-exception-handling'
221a7dea167SDimitry Andric     if (DriverArgs.hasFlag(options::OPT_mno_exception_handing,
222a7dea167SDimitry Andric                            options::OPT_mexception_handing, false))
223a7dea167SDimitry Andric       getDriver().Diag(diag::err_drv_argument_not_allowed_with)
224a7dea167SDimitry Andric           << "-fwasm-exceptions"
225a7dea167SDimitry Andric           << "-mno-exception-handling";
226*480093f4SDimitry Andric     // '-fwasm-exceptions' is not compatible with '-mno-reference-types'
227*480093f4SDimitry Andric     if (DriverArgs.hasFlag(options::OPT_mno_reference_types,
228*480093f4SDimitry Andric                            options::OPT_mexception_handing, false))
229*480093f4SDimitry Andric       getDriver().Diag(diag::err_drv_argument_not_allowed_with)
230*480093f4SDimitry Andric           << "-fwasm-exceptions"
231*480093f4SDimitry Andric           << "-mno-reference-types";
232a7dea167SDimitry Andric     // '-fwasm-exceptions' is not compatible with
233a7dea167SDimitry Andric     // '-mllvm -enable-emscripten-cxx-exceptions'
234a7dea167SDimitry Andric     for (const Arg *A : DriverArgs.filtered(options::OPT_mllvm)) {
235a7dea167SDimitry Andric       if (StringRef(A->getValue(0)) == "-enable-emscripten-cxx-exceptions")
236a7dea167SDimitry Andric         getDriver().Diag(diag::err_drv_argument_not_allowed_with)
237a7dea167SDimitry Andric             << "-fwasm-exceptions"
238a7dea167SDimitry Andric             << "-mllvm -enable-emscripten-cxx-exceptions";
239a7dea167SDimitry Andric     }
240*480093f4SDimitry Andric     // '-fwasm-exceptions' implies exception-handling and reference-types
241a7dea167SDimitry Andric     CC1Args.push_back("-target-feature");
242a7dea167SDimitry Andric     CC1Args.push_back("+exception-handling");
243*480093f4SDimitry Andric     CC1Args.push_back("-target-feature");
244*480093f4SDimitry Andric     CC1Args.push_back("+reference-types");
2450b57cec5SDimitry Andric   }
2460b57cec5SDimitry Andric }
2470b57cec5SDimitry Andric 
2480b57cec5SDimitry Andric ToolChain::RuntimeLibType WebAssembly::GetDefaultRuntimeLibType() const {
2490b57cec5SDimitry Andric   return ToolChain::RLT_CompilerRT;
2500b57cec5SDimitry Andric }
2510b57cec5SDimitry Andric 
2520b57cec5SDimitry Andric ToolChain::CXXStdlibType
2530b57cec5SDimitry Andric WebAssembly::GetCXXStdlibType(const ArgList &Args) const {
2540b57cec5SDimitry Andric   if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
2550b57cec5SDimitry Andric     StringRef Value = A->getValue();
2560b57cec5SDimitry Andric     if (Value != "libc++")
2570b57cec5SDimitry Andric       getDriver().Diag(diag::err_drv_invalid_stdlib_name)
2580b57cec5SDimitry Andric           << A->getAsString(Args);
2590b57cec5SDimitry Andric   }
2600b57cec5SDimitry Andric   return ToolChain::CST_Libcxx;
2610b57cec5SDimitry Andric }
2620b57cec5SDimitry Andric 
2630b57cec5SDimitry Andric void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
2640b57cec5SDimitry Andric                                             ArgStringList &CC1Args) const {
2650b57cec5SDimitry Andric   if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
2660b57cec5SDimitry Andric     return;
2670b57cec5SDimitry Andric 
2680b57cec5SDimitry Andric   const Driver &D = getDriver();
2690b57cec5SDimitry Andric 
2700b57cec5SDimitry Andric   if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
2710b57cec5SDimitry Andric     SmallString<128> P(D.ResourceDir);
2720b57cec5SDimitry Andric     llvm::sys::path::append(P, "include");
2730b57cec5SDimitry Andric     addSystemInclude(DriverArgs, CC1Args, P);
2740b57cec5SDimitry Andric   }
2750b57cec5SDimitry Andric 
2760b57cec5SDimitry Andric   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
2770b57cec5SDimitry Andric     return;
2780b57cec5SDimitry Andric 
2790b57cec5SDimitry Andric   // Check for configure-time C include directories.
2800b57cec5SDimitry Andric   StringRef CIncludeDirs(C_INCLUDE_DIRS);
2810b57cec5SDimitry Andric   if (CIncludeDirs != "") {
2820b57cec5SDimitry Andric     SmallVector<StringRef, 5> dirs;
2830b57cec5SDimitry Andric     CIncludeDirs.split(dirs, ":");
2840b57cec5SDimitry Andric     for (StringRef dir : dirs) {
2850b57cec5SDimitry Andric       StringRef Prefix =
2860b57cec5SDimitry Andric           llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
2870b57cec5SDimitry Andric       addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
2880b57cec5SDimitry Andric     }
2890b57cec5SDimitry Andric     return;
2900b57cec5SDimitry Andric   }
2910b57cec5SDimitry Andric 
2920b57cec5SDimitry Andric   if (getTriple().getOS() != llvm::Triple::UnknownOS) {
2930b57cec5SDimitry Andric     const std::string MultiarchTriple =
2940b57cec5SDimitry Andric         getMultiarchTriple(D, getTriple(), D.SysRoot);
2950b57cec5SDimitry Andric     addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include/" + MultiarchTriple);
2960b57cec5SDimitry Andric   }
2970b57cec5SDimitry Andric   addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
2980b57cec5SDimitry Andric }
2990b57cec5SDimitry Andric 
3000b57cec5SDimitry Andric void WebAssembly::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
3010b57cec5SDimitry Andric                                                ArgStringList &CC1Args) const {
3020b57cec5SDimitry Andric   if (!DriverArgs.hasArg(options::OPT_nostdlibinc) &&
3030b57cec5SDimitry Andric       !DriverArgs.hasArg(options::OPT_nostdincxx)) {
3040b57cec5SDimitry Andric     if (getTriple().getOS() != llvm::Triple::UnknownOS) {
3050b57cec5SDimitry Andric       const std::string MultiarchTriple =
3060b57cec5SDimitry Andric           getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
3070b57cec5SDimitry Andric       addSystemInclude(DriverArgs, CC1Args,
3080b57cec5SDimitry Andric                        getDriver().SysRoot + "/include/" + MultiarchTriple +
3090b57cec5SDimitry Andric                            "/c++/v1");
3100b57cec5SDimitry Andric     }
3110b57cec5SDimitry Andric     addSystemInclude(DriverArgs, CC1Args,
3120b57cec5SDimitry Andric                      getDriver().SysRoot + "/include/c++/v1");
3130b57cec5SDimitry Andric   }
3140b57cec5SDimitry Andric }
3150b57cec5SDimitry Andric 
3160b57cec5SDimitry Andric void WebAssembly::AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
3170b57cec5SDimitry Andric                                       llvm::opt::ArgStringList &CmdArgs) const {
3180b57cec5SDimitry Andric 
3190b57cec5SDimitry Andric   switch (GetCXXStdlibType(Args)) {
3200b57cec5SDimitry Andric   case ToolChain::CST_Libcxx:
3210b57cec5SDimitry Andric     CmdArgs.push_back("-lc++");
3220b57cec5SDimitry Andric     CmdArgs.push_back("-lc++abi");
3230b57cec5SDimitry Andric     break;
3240b57cec5SDimitry Andric   case ToolChain::CST_Libstdcxx:
3250b57cec5SDimitry Andric     llvm_unreachable("invalid stdlib name");
3260b57cec5SDimitry Andric   }
3270b57cec5SDimitry Andric }
3280b57cec5SDimitry Andric 
3290b57cec5SDimitry Andric SanitizerMask WebAssembly::getSupportedSanitizers() const {
3300b57cec5SDimitry Andric   SanitizerMask Res = ToolChain::getSupportedSanitizers();
3310b57cec5SDimitry Andric   if (getTriple().isOSEmscripten()) {
3320b57cec5SDimitry Andric     Res |= SanitizerKind::Vptr | SanitizerKind::Leak | SanitizerKind::Address;
3330b57cec5SDimitry Andric   }
3340b57cec5SDimitry Andric   return Res;
3350b57cec5SDimitry Andric }
3360b57cec5SDimitry Andric 
3370b57cec5SDimitry Andric Tool *WebAssembly::buildLinker() const {
3380b57cec5SDimitry Andric   return new tools::wasm::Linker(*this);
3390b57cec5SDimitry Andric }
340