[clang] [Driver][SYCL] Link libclang_rt.builtins.bc for spirv64 at compile time via getDeviceLibs (PR #218528)
Srividya Sundaram via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 28 11:53:53 PDT 2026
srividya-sundaram wrote:
> @srividya-sundaram, following this change, SYCL examples on godbolt.org now fail with the following error; see https://godbolt.org/z/E5rsGrenf. Note that this breaks all existing short godbolt.org links in GH issues that use `-fsycl` with Clang trunk.
>
> ```
> error: no compiler-rt builtins bitcode library '/.../lib/clang/24/lib/linux/libclang_rt.builtins-spirv64.bc' found in the clang resource directory; build compiler-rt with SPIR-V support or pass '--no-offloadlib' to compile without it
> ```
>
> Adding `--no-offloadlib` as the error suggests works around the problem. However, I'm wondering if the diagnostic should be issued for the job actions that Compiler Explorer is actually performing here. If the diagnostic is necessary; if the bitcode library is actually needed for these job actions, then we'll have to work with Compiler Explorer maintainers to update how they build the LLVM/Clang compilers hosted on godbolt.org.
`libclang_rt.builtins.bc` is compiler-rt's builtins compiled for spirv64, installed at `lib/clang/<ver>/lib/spirv64-unknown-unknown/`.
A normal LLVM build only compiles compiler-rt for the host machine. We only get the spirv64 copy if we ask for it at configure time ([llvm/runtimes/CMakeLists.txt:196-206](https://github.com/llvm/llvm-project/blob/0fcaf83fba58716609374be086b562e2f181a7bb/llvm/runtimes/CMakeLists.txt#L196-L206)),
e.x.:
```
cmake -S llvm -B build -G Ninja \
-DLLVM_ENABLE_PROJECTS=clang \
-DLLVM_RUNTIME_TARGETS="spirv64-unknown-unknown" \
-DRUNTIMES_spirv64-unknown-unknown_LLVM_ENABLE_RUNTIMES=compiler-rt
```
The Compiler Explorer build doesn't set these options, so its Clang has no spirv64 builtins.
> However, I'm wondering if the diagnostic should be issued for the job actions that Compiler Explorer is actually performing here.
It does apply to them. With `-S`, the device compile still produces the device LLVM IR module, and that's where the library gets linked.
The lookup is only skipped when no device LLVM IR module is produced, e.g. `-E`, `-fsyntax-only`, `--precompile` ([SYCL.cpp:133-143](https://github.com/llvm/llvm-project/blob/863a82fb4a2279f2a72cbfd0ad42a16e027542b6/clang/lib/Driver/ToolChains/SYCL.cpp#L133-L143)).
The mistake was making a missing library an error.
[#192897](https://github.com/llvm/llvm-project/pull/192897) added spirv64 to compiler-rt's existing GPU builtins build, alongside NVPTX and AMDGPU.
For OpenMP offloading to NVPTX and AMDGPU, the driver links compiler-rt's libclang_rt.builtins.a only if it's present, otherwise skipping it without a diagnostic ([Clang.cpp:10064-10082](https://github.com/llvm/llvm-project/blob/863a82fb4a2279f2a72cbfd0ad42a16e027542b6/clang/lib/Driver/ToolChains/Clang.cpp#L10064-L10082), from [#109152](https://github.com/llvm/llvm-project/pull/109152)).
I will update spirv64 to follow the same rule.
I'll put up a follow-up that does that: link the library when it's there, skip it quietly when it isn't.
That makes plain `-fsycl` work again on godbolt, and on any other build without the spirv64 builtins.
Since there won't be an error anymore, listing the paths checked won't be needed.
https://github.com/llvm/llvm-project/pull/218528
More information about the cfe-commits
mailing list