From 8e5b23c24e1f34203cea349ee244c4100b608fa5 Mon Sep 17 00:00:00 2001 From: Vukasin Milovanovic Date: Thu, 9 Dec 2021 09:57:41 -0800 Subject: [PATCH] Load libcufile.so with RTLD_NODELETE flag (#9872) Workaround for a known cuFile issue that can lead to segfault if cuFile library is dynamically unloaded. Using `RTLD_NODELETE` when calling `dlopen` so that the library is not unloaded in `dlclose`. Also adds a check for the result of dlopen, to help triage cuFile use issues. Authors: - Vukasin Milovanovic (https://github.com/vuule) Approvers: - Christopher Harris (https://github.com/cwharris) - Karthikeyan (https://github.com/karthikeyann) URL: https://github.com/rapidsai/cudf/pull/9872 --- cpp/src/io/utilities/file_io_utilities.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cpp/src/io/utilities/file_io_utilities.cpp b/cpp/src/io/utilities/file_io_utilities.cpp index d96bf93d10f..85a5f7e2281 100644 --- a/cpp/src/io/utilities/file_io_utilities.cpp +++ b/cpp/src/io/utilities/file_io_utilities.cpp @@ -75,8 +75,8 @@ class cufile_shim { ~cufile_shim() { - if (driver_close) driver_close(); - if (cf_lib) dlclose(cf_lib); + if (driver_close != nullptr) driver_close(); + if (cf_lib != nullptr) dlclose(cf_lib); } decltype(cuFileHandleRegister)* handle_register = nullptr; @@ -117,7 +117,8 @@ void cufile_shim::modify_cufile_json() const void cufile_shim::load_cufile_lib() { - cf_lib = dlopen("libcufile.so", RTLD_NOW); + cf_lib = dlopen("libcufile.so", RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE); + CUDF_EXPECTS(cf_lib != nullptr, "Failed to load cuFile library"); driver_open = reinterpret_cast(dlsym(cf_lib, "cuFileDriverOpen")); CUDF_EXPECTS(driver_open != nullptr, "could not find cuFile cuFileDriverOpen symbol"); driver_close = reinterpret_cast(dlsym(cf_lib, "cuFileDriverClose"));