Simply linking against libOpenCL.so tries accessing the GPU
Submitted by Niklas Haas
Assigned to mes..@..op.org
Link to original bug (#106572)
Description
$ echo 'int main() {}' > test.c && gcc -o test test.c -lOpenCL && strace -e open ./test open("/dev/dri", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 4 open("/dev/dri", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 4 open("/dev/dri", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 4 open("/dev/dri", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 4 open("/sys/dev/char/226:128/device/drm", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 4 open("/sys/dev/char/226:128/device/drm", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 5 open("/dev/dri", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 5 open("/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 5 open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 5 open("/sys/devices/system/cpu/online", O_RDONLY|O_CLOEXEC) = 5 open("/sys/dev/char/226:128/device/drm", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 5 open("/sys/dev/char/226:128/device/drm", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 5 open("/sys/dev/char/226:128/device/drm", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 5 +++ exited with 0 +++
This behavior surprises me because e.g. libGL.so does not have the same sort of behavior, and neither do libvulkan.so or other third party implementations of OpenGL/OpenCL.
Merely linking to a library should not cause any runtime GPU access. Normally I'd expect this kind of loading logic to happen when the CL device itself is initialized, similar to how OpenGL's GPU-specific drivers only get initialized when calling glXCreateContext
and ditto for vkCreateInstance / vkCreateDevice.
Context: https://bugs.gentoo.org/show_bug.cgi?id=656086
Since this behavior surprises me, I'm also filing a bug here, even though the issue is technically downstream. Maybe we could get some elaboration.
Version: git