Skip to content

Commit

Permalink
Merge pull request #2594 from kbenzie/benie/cl-core-functions-no-dlopen
Browse files Browse the repository at this point in the history
Fix invalid use of dlopen()
  • Loading branch information
kbenzie authored Jan 28, 2025
2 parents c270a6b + 264d046 commit 3a1b4c7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions source/adapters/opencl/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

ur_adapter_handle_t_::ur_adapter_handle_t_() {
#ifdef _MSC_VER

// Loading OpenCL.dll increments the libraries internal reference count.
auto handle = LoadLibraryA("OpenCL.dll");

Expand All @@ -30,17 +31,17 @@ ur_adapter_handle_t_::ur_adapter_handle_t_() {

// So we can safely decrement it here wihtout actually unloading OpenCL.dll.
FreeLibrary(handle);
#else
// Loading libOpenCL.so to get the library handle but don't dlclose it as
// this causes a segfault when attempting to call any OpenCL entry point.
auto handle = dlopen("libOpenCL.so", RTLD_LOCAL);

#else // _MSC_VER

// Use the default shared object search order (RTLD_DEFAULT) since the
// OpenCL-ICD-Loader has already been loaded into the process.
#define CL_CORE_FUNCTION(FUNC) \
FUNC = reinterpret_cast<decltype(::FUNC) *>(dlsym(handle, #FUNC));
FUNC = reinterpret_cast<decltype(::FUNC) *>(dlsym(RTLD_DEFAULT, #FUNC));
#include "core_functions.def"
#undef CL_CORE_FUNCTION

#endif
#endif // _MSC_VER
}

static ur_adapter_handle_t adapter = nullptr;
Expand Down

0 comments on commit 3a1b4c7

Please sign in to comment.