Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCL C++: printf becomes mangled c++ symbol, not working with e.g. pocl and llvm-spirv #122453

Open
davidrohr opened this issue Jan 10, 2025 · 2 comments
Labels

Comments

@davidrohr
Copy link

With clang 19.1.3, the following example

__kernel void test()
{
    printf("test");
}

compiles in OpenCL C mode to SPIRV:

clang++ --target=spirv64 -cl-std=CL2.0 -fno-integrated-objemitter -o test.spirv test.cl -O0

but in C++ for OpenCL mode

clang++ --target=spirv64 -cl-std=CLC++2021 -fno-integrated-objemitter -o test.spirv test.cl -O0

I get:

error: 0: Unresolved external reference to "_Z6printfPU3AS2Kcz".
clang++: error: spirv-link command failed with exit code 1 (use -v to see invocation)

(the same happens with -cl-std clc++).

It seems that the LLVM-SPIRV translater expects an unmangled printf symbol, but llvm emits a C++ mangled symbol.
It works when I use the experimental internal SPIRV emiter via -fintegrated-objemitter.

Also with POCL it does not work due to the mangled symbol (see pocl/pocl#1759), thus I assume llvm should produce an unmangled printf symbol as specified in OpenCL 1.2. Or all other software packages will need to adapt for clc++.

@llvmbot
Copy link
Member

llvmbot commented Jan 10, 2025

@llvm/issue-subscribers-opencl

Author: David Rohr (davidrohr)

With clang 19.1.3, the following example ``` __kernel void test() { printf("test"); } ``` compiles in OpenCL C mode to SPIRV: ``` clang++ --target=spirv64 -cl-std=CL2.0 -fno-integrated-objemitter -o test.spirv test.cl -O0 ``` but in C++ for OpenCL mode ``` clang++ --target=spirv64 -cl-std=CLC++2021 -fno-integrated-objemitter -o test.spirv test.cl -O0 ``` I get: ``` error: 0: Unresolved external reference to "_Z6printfPU3AS2Kcz". clang++: error: spirv-link command failed with exit code 1 (use -v to see invocation) ``` (the same happens with `-cl-std clc++`).

It seems that the LLVM-SPIRV translater expects an unmangled printf symbol, but llvm emits a C++ mangled symbol.
It works when I use the experimental internal SPIRV emiter via -fintegrated-objemitter.

Also with POCL it does not work due to the mangled symbol (see pocl/pocl#1759), thus I assume llvm should produce an unmangled printf symbol as specified in OpenCL 1.2. Or all other software packages will need to adapt for clc++.

@svenvh
Copy link
Member

svenvh commented Jan 10, 2025

I suspect this might be the same issue reported in KhronosGroup/SPIRV-LLVM-Translator#2908 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants