-
Notifications
You must be signed in to change notification settings - Fork 243
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
macOS: Undefined symbols for architecture arm64: [...] "___to_global"
#1288
Comments
Undefined symbols for architecture arm64: [...] "___to_global", referenced from:
Undefined symbols for architecture arm64: [...] "___to_global"
I've reproduced it in pure OpenCL now. It happens if I have more than one // poclbug.cl
kernel void poclbug(__global int* address) {
volatile global int *gi1 = to_global(address);
volatile global int *gi2 = to_global(address);
} Trying to build with poclcc:
|
This is where we convert the AS builtins to AS casts: https://github.com/pocl/pocl/blob/main/lib/llvmopencl/linker.cpp#L393 that code is quite recent, maybe I have some (iterator?) bug there so it only replaces the first occurence. Just a quick guess. |
...it could be the too common iterator invalidation bug: It erases instructions from the parent F which might invalidate the "users iterators"? We should collect the stale instructions and delete them after traversing. Maybe... |
I have a working debug build of pocl 4.x now and I think I figured it out; see my fix in #1289 ("works for me"). The bug happens much earlier than I thought. The fix is trivial but the bug probably deserves investigation: Why this didn't affect any other users? |
@JayFoxRox bear in mind that MacOS hasn't had a maintainer for a long time nor active contributors, which is why this hasn't popped up. It works well for x86. I suggest try fixing the check in the loop I mentioned above to also catch the triple underscore name and if it doesn't fix it, check if there is something being done that invalidates the iterators. @isuruf might also help you through it as he is the MacOS maintainer. (I don't use Macs personally). |
I cannot reproduce this bug with pocl 4.0 |
@isuruf I believe you need to run the chipStar or the conformance test suite (with SPIR-V mode) to produce these conversion operations through SPIR-V. |
I tried only #1288 (comment) |
Hi, I'm running pocl 4.0 on macOS (with SPIR-V) with minimal changes to https://github.com/Homebrew/homebrew-core/blob/bf6ac0be7aaf7ef66d89e8e7683f926ae981fcfa/Formula/p/pocl.rb (just bumping version and adding
LLVM_SPIRV
).However, my actual test setup is complicated. I'm unable to reproduce the following erors in OpenCL programs, but I get them when using HIP (which I ported to macOS myself).For now, I still think this is an issue in pocl, because I think the issue is in the .bc to .so linking step.(Edit: I reproduced it in pure OpenCL now; so it's almost certainly a pocl bug)
I get this problem when trying to run HIP code (I added empty line around the important bit):
The names in the .bc are still this (2 underscores; is this correct / expected for the bc?):
In the .so these are now tripple prefixed (3 underscores; which is probably good for macOS, but bad for pocl?):
I believe this is supposed to be handled by code which was modified in 4500774 (so this might be broken in 4.0; although I didn't try 3.x because I don't have LLVM 15.x anymore).
The brew formula for pocl still points at 3.x so I speculate that I'm just the first to hit this issue.
Before that patch, the code seems to have depended on the mangling by the compiler to generate the names. Now it seems to hardcode a specific mangling.
This assumption doesn't respect that macOS / OSX has a
_
prefix for C functions (as part of the MachO ABI), so these are actually___to_global
(= 3 underscores) etc.I've tried to find out which tool does the .bc → .so translation (llvm-codegen I guess?) and I also tried to find the part where the
_
is added to the function name, but I wasn't able to.Maybe someone more familiar can take a look?
Also, if someone can show some OpenCL code which generates these symbols, that'd be nice.
The text was updated successfully, but these errors were encountered: