From 076705fe8e5e3013141a436884f1468a1a3acd02 Mon Sep 17 00:00:00 2001 From: Faidon Liambotis Date: Fri, 7 Oct 2022 15:45:21 +0300 Subject: [PATCH] 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. --- debian/patches/series | 2 ++ debian/patches/wasm-compiler-rt-default.diff | 31 ++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 debian/patches/wasm-compiler-rt-default.diff diff --git a/debian/patches/series b/debian/patches/series index fda038f5..1faf4424 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -148,6 +148,8 @@ compilerrt-builtins-arch-fix-armhf.diff compilerrt-build-scudo-standalone-option.diff wasm-ld-path.diff python3-scan-build.py +wasm-compiler-rt-default.diff +issue-54242.diff revert-update-doc.diff fix-typo.diff ubuntu-kinetic.patch diff --git a/debian/patches/wasm-compiler-rt-default.diff b/debian/patches/wasm-compiler-rt-default.diff new file mode 100644 index 00000000..351fcc79 --- /dev/null +++ b/debian/patches/wasm-compiler-rt-default.diff @@ -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,