[compiler-rt] 5082803 - [compiler-rt] Partially enable building compiler-rt unit tests for spirv64 target (#215717)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 13 00:24:23 PDT 2026


Author: jinge90
Date: 2026-08-13T15:24:19+08:00
New Revision: 50828033d5bb75b5bc75f695ece5fdcf2df76d1b

URL: https://github.com/llvm/llvm-project/commit/50828033d5bb75b5bc75f695ece5fdcf2df76d1b
DIFF: https://github.com/llvm/llvm-project/commit/50828033d5bb75b5bc75f695ece5fdcf2df76d1b.diff

LOG: [compiler-rt] Partially enable building compiler-rt unit tests for spirv64 target (#215717)

Currently, compilation/linking error will happen for all compiler-rt
builtin unit test when building them for spirv64 target, there are a
bunch of problem to resolve, this patch is the 1st one aiming to resolve
following 2 problems in building phase:
1. fatal error: error in backend:
SPV_EXT_relaxed_printf_string_address_space is required because printf
uses a format string not in constant address space.
2. -lc/-lm flags are not recognized by spirv64 toolchain.

For 1, unit tests are plain C source files and use printf, the format
string is a C-string which is not decorated by any address space, so
need to apply SPV_EXT_relaxed_printf_string_address_space to allow it
for spirv64.
For 2, spirv64 toolchain has not supported to use static archive
library, so this -lc/-lm is not accepted by clang. So, we need to use
bitcode libc in device compilation phase via -mlink-builtin-bitcode.
Currently, we only link libc since libm spirv64 library has not been
landed in community. In order to build compiler-rt tests for spirv64, we
need to enable LLVM libc when building llvm-project.

Using following command to build llvm-project:
cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="clang"
-DRUNTIMES_spirv64-unknown-unknown_LLVM_ENABLE_RUNTIMES="compiler-rt;libc"
-DLLVM_RUNTIME_TARGETS="default;spirv64-unknown-unknown"
-DRUNTIMES_spirv64-unknown-unknown_COMPILER_RT_INCLUDE_TESTS=ON
-DRUNTIMES_spirv64-unknown-unknown_COMPILER_RT_EMULATOR=/bin/true
ninja all
ninja check-compiler-rt-spirv64-unknown-unknown
Before applying the PR, the building result is:
Total Discovered Tests: 270
  Unsupported: 120 (44.44%)
  Passed     :   1 (0.37%)
  Failed     : 149 (55.19%)
After applying the PR, the building result is:
Total Discovered Tests: 270
  Unsupported: 120 (44.44%)
  Passed     : 119 (44.07%)
  Failed     :  31 (11.48%)

---------

Signed-off-by: jinge90 <ge.jin at intel.com>

Added: 
    

Modified: 
    compiler-rt/test/builtins/CMakeLists.txt
    compiler-rt/test/builtins/Unit/lit.cfg.py

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/builtins/CMakeLists.txt b/compiler-rt/test/builtins/CMakeLists.txt
index 6e6fabd3e2c15..9dc2754446c49 100644
--- a/compiler-rt/test/builtins/CMakeLists.txt
+++ b/compiler-rt/test/builtins/CMakeLists.txt
@@ -73,6 +73,9 @@ foreach(arch ${BUILTIN_TEST_ARCH})
     elseif("${arch}" MATCHES "nvptx")
       list(APPEND BUILTINS_TEST_TARGET_CFLAGS
            -Wno-multi-gpu -flto -march=native -nogpulib -startfiles -stdlib)
+    elseif("${arch}" MATCHES "spirv64")
+      list(APPEND BUILTINS_TEST_TARGET_CFLAGS
+	       -Wno-multi-gpu -nogpulib -mllvm -spirv-ext=+SPV_EXT_relaxed_printf_string_address_space)
     endif()
     list(APPEND BUILTINS_TEST_TARGET_CFLAGS --target=${COMPILER_RT_DEFAULT_TARGET_TRIPLE})
     string(REPLACE ";" " " BUILTINS_TEST_TARGET_CFLAGS "${BUILTINS_TEST_TARGET_CFLAGS}")

diff  --git a/compiler-rt/test/builtins/Unit/lit.cfg.py b/compiler-rt/test/builtins/Unit/lit.cfg.py
index f1ebd61438bd9..05f97844f5470 100644
--- a/compiler-rt/test/builtins/Unit/lit.cfg.py
+++ b/compiler-rt/test/builtins/Unit/lit.cfg.py
@@ -83,9 +83,29 @@ def get_libgcc_file_name():
         linker_supports_start_group = get_required_attr(
             config, "linker_supports_start_group"
         )
+        if "spirv" in config.target_arch:
+            builtins_bitcode_library = os.path.join(
+                config.compiler_rt_libdir,
+                "libclang_rt.builtins%s.bc" % config.target_suffix,
+            )
+            librt_flags = (
+                "-Xclang -mlink-builtin-bitcode -Xclang "
+                + builtins_bitcode_library
+                + " "
+            )
+            libc_bitcode_library = os.path.join(
+                config.llvm_shlib_dir, config.target_triple, "libcbitcode.bc"
+            )
+            if os.path.exists(libc_bitcode_library):
+                librt_flags += (
+                    "-Xclang -mlink-builtin-bitcode -Xclang "
+                    + libc_bitcode_library
+                    + " "
+                )
+            config.substitutions.append(("%librt ", librt_flags))
         # Check if the linker supports --start-group and --end-group
         # For nvptx64 target, it falls back to the default.
-        if linker_supports_start_group and "nvptx" not in config.target_arch:
+        elif linker_supports_start_group and "nvptx" not in config.target_arch:
             config.substitutions.append(
                 (
                     "%librt ",


        


More information about the llvm-commits mailing list