Default to compiler-rt for WebAssembly (wasm32/64)

Our packaging overrides the upstream choice for rtlib to default always
to libgcc. Unfortunately, libgcc is not available for WebAssembly
(wasm32/wasm64 targets). This makes every build to -target
wasm32-unknown-wasi fail, unless one passes --rtlib=compiler-rt.

Patch the upstream source to default, and only accept, compiler-rt for
the WebAssembly target to make everything work out of the box. This
mirrors similar code that the upstream Darwin and Fuchsia targets have.

GCC seems fairly far from supporting WebAssembly. If/when that day
comes, this patch can be dropped.
This commit is contained in:
Faidon Liambotis 2022-10-07 15:45:21 +03:00
parent bcf5c6f89b
commit a94a2fe7c3
2 changed files with 32 additions and 0 deletions

View File

@ -138,6 +138,7 @@ llvm-runtimes-builtins-build-check.diff
compilerrt-builtins-arch-fix-armhf.diff
compilerrt-build-scudo-standalone-option.diff
wasm-ld-path.diff
wasm-compiler-rt-default.diff
issue-54242.diff
revert-update-doc.diff
unwind-force-pthread-dl.diff

View File

@ -0,0 +1,31 @@
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -369,6 +369,18 @@ ToolChain::RuntimeLibType WebAssembly::G
return ToolChain::RLT_CompilerRT;
}
+ToolChain::RuntimeLibType WebAssembly::GetRuntimeLibType(
+ const ArgList &Args) const {
+ if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) {
+ StringRef Value = A->getValue();
+ if (Value != "compiler-rt")
+ getDriver().Diag(clang::diag::err_drv_unsupported_rtlib_for_platform)
+ << Value << "WebAssembly";
+ }
+
+ return ToolChain::RLT_CompilerRT;
+}
+
ToolChain::CXXStdlibType
WebAssembly::GetCXXStdlibType(const ArgList &Args) const {
if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
--- a/clang/lib/Driver/ToolChains/WebAssembly.h
+++ b/clang/lib/Driver/ToolChains/WebAssembly.h
@@ -61,6 +61,7 @@ private:
llvm::opt::ArgStringList &CC1Args,
Action::OffloadKind DeviceOffloadKind) const override;
RuntimeLibType GetDefaultRuntimeLibType() const override;
+ RuntimeLibType GetRuntimeLibType(const llvm::opt::ArgList &Args) const override;
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override;
void
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,