[libc-commits] [libc] c723356 - [compiler-rt][libc][GPU] Fix 7 builtin unit test build failure for spirv64 targets (#236324)
via libc-commits
libc-commits at lists.llvm.org
Sun Nov 1 19:14:49 PST 2026
Author: jinge90
Date: 2026-11-02T11:14:44+08:00
New Revision: c7233566764726c242ffa2335b0aca9781c57235
URL: https://github.com/llvm/llvm-project/commit/c7233566764726c242ffa2335b0aca9781c57235
DIFF: https://github.com/llvm/llvm-project/commit/c7233566764726c242ffa2335b0aca9781c57235.diff
LOG: [compiler-rt][libc][GPU] Fix 7 builtin unit test build failure for spirv64 targets (#236324)
When building compiler-rt builtin unit test for spirv64 target, we
encountered a bunch of build failure due to missing symbols from libm
and libc. This PR adds part of required symbols needed by those tests
which can make 7 failed unit tests to build pass.
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 the fix, the build result was:
Total Discovered Tests: 275
Unsupported: 125 (45.45%)
Passed : 123 (44.73%)
Failed : 27 (9.82%)
After the fix, the build result was:
Total Discovered Tests: 275
Unsupported: 125 (45.45%)
Passed : 128 (46.55%)
Failed : 22 (8.00%)
All libc and libm symbols added are simple functions without using RPC
mechanism and verified for spirv64 targets with Level_Zero and Intel GPU
devices on Linux platform.
---------
Signed-off-by: jinge90 <ge.jin at intel.com>
Co-authored-by: Joseph Huber <huberjn at outlook.com>
Added:
Modified:
compiler-rt/test/builtins/Unit/divsc3_test.c
compiler-rt/test/builtins/Unit/divtc3_test.c
compiler-rt/test/builtins/Unit/divxc3_test.c
compiler-rt/test/builtins/Unit/lit.cfg.py
compiler-rt/test/builtins/Unit/muldc3_test.c
compiler-rt/test/builtins/Unit/mulsc3_test.c
compiler-rt/test/builtins/Unit/mulxc3_test.c
libc/config/gpu/spirv/entrypoints.txt
Removed:
################################################################################
diff --git a/compiler-rt/test/builtins/Unit/divsc3_test.c b/compiler-rt/test/builtins/Unit/divsc3_test.c
index 05a073b4375c72..d37839702cdf45 100644
--- a/compiler-rt/test/builtins/Unit/divsc3_test.c
+++ b/compiler-rt/test/builtins/Unit/divsc3_test.c
@@ -1,4 +1,4 @@
-// RUN: %clang_builtins %s %librt -lm -o %t && %run %t
+// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: librt_has_divsc3
// REQUIRES: c99-complex
diff --git a/compiler-rt/test/builtins/Unit/divtc3_test.c b/compiler-rt/test/builtins/Unit/divtc3_test.c
index 1e1cfae766e9af..e77722a0940002 100644
--- a/compiler-rt/test/builtins/Unit/divtc3_test.c
+++ b/compiler-rt/test/builtins/Unit/divtc3_test.c
@@ -1,4 +1,4 @@
-// RUN: %clang_builtins %s %librt -lm -o %t && %run %t
+// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: librt_has_divtc3
// REQUIRES: c99-complex
diff --git a/compiler-rt/test/builtins/Unit/divxc3_test.c b/compiler-rt/test/builtins/Unit/divxc3_test.c
index d97e72a5c013a6..f924acf672b43f 100644
--- a/compiler-rt/test/builtins/Unit/divxc3_test.c
+++ b/compiler-rt/test/builtins/Unit/divxc3_test.c
@@ -1,4 +1,4 @@
-// RUN: %clang_builtins %s %librt -lm -o %t && %run %t
+// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: librt_has_divxc3
// REQUIRES: x86-target-arch
// UNSUPPORTED: target=powerpc64{{.*}}
diff --git a/compiler-rt/test/builtins/Unit/lit.cfg.py b/compiler-rt/test/builtins/Unit/lit.cfg.py
index cc2b905c68bec1..e011d6b8214c65 100644
--- a/compiler-rt/test/builtins/Unit/lit.cfg.py
+++ b/compiler-rt/test/builtins/Unit/lit.cfg.py
@@ -53,6 +53,8 @@ def get_libgcc_file_name():
config.test_source_root = os.path.dirname(__file__)
# Path to the static library
+# On generic ELF targets %librt also links libm (-lm); spirv links libm.bc
+# instead.
is_msvc = get_required_attr(config, "is_msvc")
if is_msvc:
base_lib = os.path.join(
@@ -102,6 +104,15 @@ def get_libgcc_file_name():
+ libc_bitcode_library
+ " "
)
+ libm_bitcode_library = os.path.join(
+ config.llvm_shlib_dir, config.target_triple, "libm.bc"
+ )
+ if os.path.exists(libm_bitcode_library):
+ librt_flags += (
+ "-Xclang -mlink-builtin-bitcode -Xclang "
+ + libm_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.
@@ -109,11 +120,11 @@ def get_libgcc_file_name():
config.substitutions.append(
(
"%librt ",
- "-lm -Wl,--start-group " + base_lib + " -lc -Wl,--end-group ",
+ "-lm -Wl,--start-group " + base_lib + " -lc -Wl,--end-group -lm ",
)
)
else:
- config.substitutions.append(("%librt ", "-lm " + base_lib + " -lc "))
+ config.substitutions.append(("%librt ", "-lm " + base_lib + " -lc -lm "))
builtins_test_crt = get_required_attr(config, "builtins_test_crt")
if builtins_test_crt:
diff --git a/compiler-rt/test/builtins/Unit/muldc3_test.c b/compiler-rt/test/builtins/Unit/muldc3_test.c
index 1787b83f771b39..ff676cad3400eb 100644
--- a/compiler-rt/test/builtins/Unit/muldc3_test.c
+++ b/compiler-rt/test/builtins/Unit/muldc3_test.c
@@ -1,4 +1,4 @@
-// RUN: %clang_builtins %s -ffp-contract=off %librt -lm -o %t && %run %t
+// RUN: %clang_builtins %s -ffp-contract=off %librt -o %t && %run %t
// REQUIRES: librt_has_muldc3
// REQUIRES: c99-complex
diff --git a/compiler-rt/test/builtins/Unit/mulsc3_test.c b/compiler-rt/test/builtins/Unit/mulsc3_test.c
index e7cac4616a68b8..4f46b9c69ba4a1 100644
--- a/compiler-rt/test/builtins/Unit/mulsc3_test.c
+++ b/compiler-rt/test/builtins/Unit/mulsc3_test.c
@@ -1,4 +1,4 @@
-// RUN: %clang_builtins %s %librt -lm -o %t && %run %t
+// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: librt_has_mulsc3
// REQUIRES: c99-complex
diff --git a/compiler-rt/test/builtins/Unit/mulxc3_test.c b/compiler-rt/test/builtins/Unit/mulxc3_test.c
index b07f11f6d27fef..2a5f4e2abdf29e 100644
--- a/compiler-rt/test/builtins/Unit/mulxc3_test.c
+++ b/compiler-rt/test/builtins/Unit/mulxc3_test.c
@@ -1,4 +1,4 @@
-// RUN: %clang_builtins %s %librt -lm -o %t && %run %t
+// RUN: %clang_builtins %s %librt -o %t && %run %t
// REQUIRES: librt_has_mulxc3
// UNSUPPORTED: target=powerpc64{{.*}}
// REQUIRES: x86-target-arch
diff --git a/libc/config/gpu/spirv/entrypoints.txt b/libc/config/gpu/spirv/entrypoints.txt
index 36c98339582cd0..5b21d12c84af24 100644
--- a/libc/config/gpu/spirv/entrypoints.txt
+++ b/libc/config/gpu/spirv/entrypoints.txt
@@ -85,9 +85,27 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.strings.strcasecmp
libc.src.strings.strncasecmp
+ # stdlib.h entrypoints
+ libc.src.stdlib.abs
+ libc.src.stdlib.div
+ libc.src.stdlib.labs
+ libc.src.stdlib.ldiv
+ libc.src.stdlib.llabs
+ libc.src.stdlib.lldiv
)
set(TARGET_LIBM_ENTRYPOINTS
+ # math.h entrypoints
+ libc.src.math.logbf
+ # complex.h entrypoints
+ libc.src.complex.cabs
+ libc.src.complex.cabsf
+ libc.src.complex.creal
+ libc.src.complex.crealf
+ libc.src.complex.cimag
+ libc.src.complex.cimagf
+ libc.src.complex.conj
+ libc.src.complex.conjf
)
if(LIBC_TYPES_HAS_FLOAT16)
More information about the libc-commits
mailing list