Bug 106572 - Simply linking against libOpenCL.so tries accessing the GPU
Summary: Simply linking against libOpenCL.so tries accessing the GPU
Status: RESOLVED MOVED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: git
Hardware: Other All
: medium normal
Assignee: mesa-dev
QA Contact: mesa-dev
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-19 02:03 UTC by Niklas Haas
Modified: 2019-09-18 20:27 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Niklas Haas 2018-05-19 02:03:35 UTC
$ 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.
Comment 1 GitLab Migration User 2019-09-18 20:27:09 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/mesa/mesa/issues/1025.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.