bashbaug / opencl-runtime-loader

OpenCL Runtime Loader Library
MIT License
2 stars 0 forks source link

Be safer about null dlopen returns #20

Closed rcombs closed 3 years ago

rcombs commented 4 years ago

Currently, if _sclOpenICDLoader returns NULL, we still pass the result to _sclGetFunctionAddress. This happens to be handled gracefully in glibc, where RTLD_DEFAULT is NULL, but that's not guaranteed. As far as I can tell, Windows's behavior when NULL is passed to GetProcAddress is more or less identical, but completely undocumented. We shouldn't rely on this.

This could actually lead to infinite recursion depending on linker configuration, since we could end up loading and calling into our own copy of clGetPlatformIDs if we do an RTLD_DEFAULT search. If we get NULL back from _sclOpenICDLoader (or _sclGetICDLoaderHandle, after #18), we should error out immediately.