<html>
    <head>
      <base href="https://bugs.freedesktop.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Simply linking against libOpenCL.so tries accessing the GPU"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=106572">106572</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Simply linking against libOpenCL.so tries accessing the GPU
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Mesa
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>git
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Mesa core
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>mesa-dev@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>bugs.freedesktop@haasn.xyz
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>mesa-dev@lists.freedesktop.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ 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: <a href="https://bugs.gentoo.org/show_bug.cgi?id=656086">https://bugs.gentoo.org/show_bug.cgi?id=656086</a>

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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
          <li>You are the QA Contact for the bug.</li>
      </ul>
    </body>
</html>