Source: llvm-toolchain-22
Version: 1:22.1.6-1
Severity: normal
Tags: patch
Dear Maintainer,
Currently, clang searches for compiler-rt builtins for WASI preview
targets (wasm32-wasip{1,2,3}) in the wrong place. Namely, instead of
searching for
/usr/lib/llvm-22/lib/clang/22/lib/wasi/libclang_rt.builtins-wasm32.a,
clang-22 instead searches for
/usr/lib/llvm-22/lib/clang/22/lib/wasip{1,2,3}/libclang_rt.builtins-wasm32.a.
This bug was originally reported in Ubuntu LP: #2152147[1] but is also
reproducible upstream. I have submitted an issue[2] and a PR[3] to
the upstream LLVM project.
I have included a patch which fixes the problem by making clang search
for wasip{1,2,3} builtins under the "wasi" folder which compiler-rt
installs them in.
Steps to reproduce in a fresh Debian sid install:
# apt update
# apt install -y clang-22 libclang-rt-22-dev-wasm32 libc++-22-dev-wasm32
lld-22
$ touch test.c
$ clang-22 --target=wasm32-wasip1 test.c
wasm-ld-22: error: cannot open
/usr/lib/llvm-22/lib/clang/22/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a:
No such file or directory
clang-22: error: linker command failed with exit code 1 (use -v to see
invocation)
[1]:
https://bugs.launchpad.net/ubuntu/+source/llvm-toolchain-22/+bug/2152147
[2]: https://github.com/llvm/llvm-project/issues/200500
[3]: https://github.com/llvm/llvm-project/pull/200501
Description: Fix path lookup for WASI previews
getOS() returns the wrong path for WASI preview targets (wasm-wasip1,
wasm-wasip2, and wasm-wasip3). For example, passing
--target=wasm32-wasip1 returns "wasip1". However,
libclang-rt-22-dev-wasm32 installs wasm32 compiler-rt builtins under
the "wasi" directory, not the "wasip1" directory, meaning that the
toolchain is unable to find the builtins it needs.
.
This patch makes getOS() return the "wasi" directory when any WASI
preview target is used, allowing the toolchain to find the proper wasi
builtins.
Author: Max Gilmour <[email protected]>
Bug: https://github.com/llvm/llvm-project/issues/200500
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/llvm-toolchain-22/+bug/2152147
Applied-Upstream: https://github.com/llvm/llvm-project/pull/200501
Last-Update: 2026-05-29
---
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -717,6 +717,10 @@
return "sunos";
case llvm::Triple::AIX:
return "aix";
+ case llvm::Triple::WASIp1:
+ case llvm::Triple::WASIp2:
+ case llvm::Triple::WASIp3:
+ return "wasi";
default:
return getOS();
}