Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid use of dlopen() #2594

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading