From e2db37ca8d6b8514d870e86282f2e66f568487e6 Mon Sep 17 00:00:00 2001 From: "Jonathan R. Madsen" Date: Sun, 25 Feb 2024 21:14:27 -0600 Subject: [PATCH] Search for rocprofiler_set_api_table(...) via RTLD_DEFAULT (#56) * Search for rocprofiler_set_api_table(...) via RTLD_DEFAULT - check if rocprofiler_set_api_table function has already been loaded via dlsym(RTLD_DEFAULT, ...) - fix warning about conflicting ROCM_DEP_ROCMCORE and ROCPROFILER_REGISTER_DEP_ROCMCORE * Bump version to 0.4.0 --- VERSION | 2 +- cmake/rocprofiler_register_options.cmake | 3 ++- .../rocprofiler-register/rocprofiler_register.cpp | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 0d91a54c7d..1d0ba9ea18 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.0 +0.4.0 diff --git a/cmake/rocprofiler_register_options.cmake b/cmake/rocprofiler_register_options.cmake index 52ce6f955d..41e31bd088 100644 --- a/cmake/rocprofiler_register_options.cmake +++ b/cmake/rocprofiler_register_options.cmake @@ -54,7 +54,8 @@ if(ROCPROFILER_REGISTER_BUILD_CI AND NOT ROCPROFILER_REGISTER_ENABLE_CLANG_TIDY) FORCE) endif() -if(NOT ROCM_DEP_ROCMCORE EQUAL ROCPROFILER_REGISTER_DEP_ROCMCORE) +if((ROCM_DEP_ROCMCORE AND NOT ROCPROFILER_REGISTER_DEP_ROCMCORE) + OR (NOT ROCM_DEP_ROCMCORE AND ROCPROFILER_REGISTER_DEP_ROCMCORE)) message( AUTHOR_WARNING "Conflicting option values: ROCM_DEP_ROCMCORE = ${ROCM_DEP_ROCMCORE} and ROCPROFILER_REGISTER_DEP_ROCMCORE = ${ROCPROFILER_REGISTER_DEP_ROCMCORE}" diff --git a/source/lib/rocprofiler-register/rocprofiler_register.cpp b/source/lib/rocprofiler-register/rocprofiler_register.cpp index 3d086e2bcf..7c09d2f09b 100644 --- a/source/lib/rocprofiler-register/rocprofiler_register.cpp +++ b/source/lib/rocprofiler-register/rocprofiler_register.cpp @@ -273,6 +273,18 @@ rocp_load_rocprofiler_lib(std::string _rocp_reg_lib) if(rocprofiler_set_api_table) rocprofiler_lib_config_fn = &rocprofiler_set_api_table; + // return if found via LD_PRELOAD + if(rocprofiler_lib_config_fn) + return std::make_tuple(rocprofiler_lib_handle, rocprofiler_lib_config_fn); + + // look to see if entrypoint function is already a symbol + *(void**) (&rocprofiler_lib_config_fn) = + dlsym(RTLD_DEFAULT, rocprofiler_lib_register_entrypoint); + + // return if found via RTLD_DEFAULT + if(rocprofiler_lib_config_fn) + return std::make_tuple(rocprofiler_lib_handle, rocprofiler_lib_config_fn); + if(_rocp_reg_lib.empty()) _rocp_reg_lib = rocprofiler_lib_name; auto _rocp_reg_lib_path = fs::path{ _rocp_reg_lib };