diff --git a/source/lib/common/elf_utils.cpp b/source/lib/common/elf_utils.cpp index 54bb5382..408518a9 100644 --- a/source/lib/common/elf_utils.cpp +++ b/source/lib/common/elf_utils.cpp @@ -89,6 +89,11 @@ ElfInfo::has_symbol(std::regex&& _re) const { if(!itr.name.empty() && std::regex_search(itr.name, _re)) return true; } + // For stripped binaries + for(const auto& itr : dynamic_symbol_entries) + { + if(!itr.name.empty() && std::regex_search(itr.name, _re)) return true; + } return false; } @@ -96,12 +101,13 @@ ElfInfo::has_symbol(std::regex&& _re) const ElfInfo read(const std::string& _inp) { - auto _info = ElfInfo{_inp}; - auto& reader = _info.reader; - auto& sections = _info.sections; - auto& symbol_entries = _info.symbol_entries; - auto& dynamic_entries = _info.dynamic_entries; - auto& reloc_entries = _info.reloc_entries; + auto _info = ElfInfo{_inp}; + auto& reader = _info.reader; + auto& sections = _info.sections; + auto& symbol_entries = _info.symbol_entries; + auto& dynamic_symbol_entries = _info.dynamic_symbol_entries; + auto& dynamic_entries = _info.dynamic_entries; + auto& reloc_entries = _info.reloc_entries; ROCP_TRACE << "\nReading " << _inp; @@ -148,10 +154,17 @@ read(const std::string& _inp) if(psec->get_type() == ELFIO::SHT_SYMTAB) { const ELFIO::symbol_section_accessor _symbols(reader, psec); - ROCP_TRACE << " Number of symbol_entries: " << _symbols.get_symbols_num(); + ROCP_TRACE << " Number of symbol entries: " << _symbols.get_symbols_num(); for(ELFIO::Elf_Xword k = 0; k < _symbols.get_symbols_num(); ++k) symbol_entries.emplace_back(k, _symbols); } + else if(psec->get_type() == ELFIO::SHT_DYNSYM) + { + const ELFIO::symbol_section_accessor _symbols(reader, psec); + ROCP_TRACE << " Number of dynamic symbol entries: " << _symbols.get_symbols_num(); + for(ELFIO::Elf_Xword k = 0; k < _symbols.get_symbols_num(); ++k) + dynamic_symbol_entries.emplace_back(k, _symbols); + } else if(psec->get_type() == ELFIO::SHT_DYNAMIC) { const ELFIO::dynamic_section_accessor dynamic{reader, psec}; @@ -175,6 +188,13 @@ read(const std::string& _inp) ROCP_TRACE << " [" << k << "] " << symbol_entries.at(k).name; } + ROCP_TRACE << "Dynamic Symbols:"; + for(size_t k = 0; k < dynamic_symbol_entries.size(); ++k) + { + if(!dynamic_symbol_entries.at(k).name.empty()) + ROCP_TRACE << " [" << k << "] " << dynamic_symbol_entries.at(k).name; + } + ROCP_TRACE << "Dynamic entries:"; for(size_t k = 0; k < dynamic_entries.size(); ++k) { diff --git a/source/lib/common/elf_utils.hpp b/source/lib/common/elf_utils.hpp index 33946bad..7ddc9697 100644 --- a/source/lib/common/elf_utils.hpp +++ b/source/lib/common/elf_utils.hpp @@ -86,12 +86,13 @@ struct ElfInfo { explicit ElfInfo(std::string); - std::string filename = {}; - ELFIO::elfio reader = {}; - std::vector sections = {}; - std::vector symbol_entries = {}; - std::vector dynamic_entries = {}; - std::vector reloc_entries = {}; + std::string filename = {}; + ELFIO::elfio reader = {}; + std::vector sections = {}; + std::vector symbol_entries = {}; + std::vector dynamic_symbol_entries = {}; + std::vector dynamic_entries = {}; + std::vector reloc_entries = {}; bool has_symbol(std::regex&&) const; diff --git a/source/lib/rocprofiler-sdk/registration.cpp b/source/lib/rocprofiler-sdk/registration.cpp index 2c5dfcd3..ba5d0b39 100644 --- a/source/lib/rocprofiler-sdk/registration.cpp +++ b/source/lib/rocprofiler-sdk/registration.cpp @@ -246,15 +246,16 @@ find_clients() { for(const auto& itr : env) { - ROCP_INFO << "[env] searching " << itr << " for rocprofiler_configure"; + ROCP_INFO << "[ROCP_TOOL_LIBRARIES] searching " << itr << " for rocprofiler_configure"; if(fs::exists(itr)) { auto elfinfo = common::elf_utils::read(itr); if(!elfinfo.has_symbol(std::regex{"^rocprofiler_configure$"})) { - ROCP_FATAL << "rocprofiler tool library " << itr - << " did not contain rocprofiler_configure symbol"; + ROCP_FATAL << "[ROCP_TOOL_LIBRARIES] rocprofiler-sdk tool library '" << itr + << "' did not contain rocprofiler_configure symbol (search method: " + "ELF parsing)"; } } @@ -262,15 +263,14 @@ find_clients() if(!handle) { - ROCP_WARNING << "[env] " << itr - << " is not already loaded, doing a local lazy dlopen..."; + ROCP_INFO << "[ROCP_TOOL_LIBRARIES] '" << itr + << "' is not already loaded, doing a local lazy dlopen..."; handle = dlopen(itr.c_str(), RTLD_LOCAL | RTLD_LAZY); } if(!handle) { - ROCP_ERROR << "error dlopening " << itr; - continue; + ROCP_FATAL << "[ROCP_TOOL_LIBRARIES] error dlopening '" << itr << "'"; } for(const auto& ditr : data) @@ -286,8 +286,9 @@ find_clients() { auto _sym = rocprofiler_configure_dlsym(handle); // FATAL bc they explicitly said this was a tool library - ROCP_FATAL_IF(!_sym) << "rocprofiler tool library " << itr - << " did not contain rocprofiler_configure symbol"; + ROCP_FATAL_IF(!_sym) + << "[ROCP_TOOL_LIBRARIES] rocprofiler-sdk tool library '" << itr + << "' did not contain rocprofiler_configure symbol (search method: dlsym)"; if(is_unique_configure_func(_sym)) emplace_client(itr, handle, _sym); } } diff --git a/tests/c-tool/CMakeLists.txt b/tests/c-tool/CMakeLists.txt index 5a35c0a2..4dcca34d 100644 --- a/tests/c-tool/CMakeLists.txt +++ b/tests/c-tool/CMakeLists.txt @@ -37,3 +37,26 @@ set_tests_properties( "Test C tool \\(priority=0\\) is using rocprofiler-sdk v([0-9]+\\.[0-9]+\\.[0-9]+)" FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}") + +# this test uses ROCP_TOOL_LIBRARIES instead of LD_PRELOAD +add_test(NAME test-c-tool-rocp-tool-lib-execute COMMAND $ 1) + +set(c-tool-rocp-tool-lib-env + "${ROCPROFILER_MEMCHECK_PRELOAD_ENV}" + "ROCP_TOOL_LIBRARIES=$" + "LD_LIBRARY_PATH=$:$ENV{LD_LIBRARY_PATH}" + ) + +set_tests_properties( + test-c-tool-rocp-tool-lib-execute + PROPERTIES + TIMEOUT + 45 + LABELS + "integration-tests" + ENVIRONMENT + "${c-tool-rocp-tool-lib-env}" + PASS_REGULAR_EXPRESSION + "Test C tool \\(priority=0\\) is using rocprofiler-sdk v([0-9]+\\.[0-9]+\\.[0-9]+)" + FAIL_REGULAR_EXPRESSION + "${ROCPROFILER_DEFAULT_FAIL_REGEX}") diff --git a/tests/tools/CMakeLists.txt b/tests/tools/CMakeLists.txt index 4643ca70..5e481462 100644 --- a/tests/tools/CMakeLists.txt +++ b/tests/tools/CMakeLists.txt @@ -38,3 +38,14 @@ set_target_properties( VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} INSTALL_RPATH "\$ORIGIN:\$ORIGIN/..") + +if(NOT CMAKE_STRIP) + find_program(CMAKE_STRIP NAMES strip REQUIRED) +endif() + +add_custom_command( + TARGET rocprofiler-sdk-c-tool + POST_BUILD + COMMAND ${CMAKE_STRIP} $ + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Stripping rocprofiler-sdk-c-tool...")