diff --git a/clang/lib/Driver/ToolChains/WebAssembly.h b/clang/lib/Driver/ToolChains/WebAssembly.h --- a/clang/lib/Driver/ToolChains/WebAssembly.h +++ b/clang/lib/Driver/ToolChains/WebAssembly.h @@ -71,6 +71,7 @@ const char *getDefaultLinker() const override { return "wasm-ld"; } Tool *buildLinker() const override; + std::string getCompilerRTPath() const; }; } // end namespace toolchains diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp --- a/clang/lib/Driver/ToolChains/WebAssembly.cpp +++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -155,6 +155,19 @@ } } +std::string WebAssembly::getCompilerRTPath() const { + // If we're doing LTO and we have an LTO library available, use it. + const auto &D = getDriver(); + if (D.isUsingLTO()) { + auto Dir = AppendLTOLibDir(ToolChain::getCompilerRTPath()); + if (llvm::sys::fs::exists(Dir)) + return Dir; + } + + // Otherwise just use the default. + return ToolChain::getCompilerRTPath(); +} + bool WebAssembly::IsMathErrnoDefault() const { return false; } bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; }