#1138702 llvm-toolchain-22: WASI preview targets can't find compiler-rt builtins in flat library layout

#1138702#5
Date:
2026-06-02 15:15:43 UTC
From:
To:
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