SWDEV-361912 - Fix kernel demangling
Older GNU C++ runtimes cannot demangle symbol names generated by recent versions of LLVM. To work around this issue, use the LLVM demangler to process kernel names. Change-Id: I595f900d06360bb5acce542955cf1f5aed81f00e
This commit is contained in:
@@ -20,6 +20,14 @@
|
||||
## IN THE SOFTWARE.
|
||||
################################################################################
|
||||
|
||||
find_package(amd_comgr REQUIRED CONFIG
|
||||
PATHS
|
||||
/opt/rocm/
|
||||
PATH_SUFFIXES
|
||||
lib/cmake/amd_comgr
|
||||
)
|
||||
MESSAGE(STATUS "Code Object Manager found at ${amd_comgr_DIR}.")
|
||||
|
||||
file(GLOB FILE_SOURCES "*.cpp")
|
||||
add_library(file_plugin ${LIBRARY_TYPE} ${FILE_SOURCES})
|
||||
|
||||
@@ -35,7 +43,7 @@ target_include_directories(file_plugin PRIVATE ${PROJECT_SOURCE_DIR}/inc)
|
||||
|
||||
target_link_options(file_plugin PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exportmap -Wl,--no-undefined)
|
||||
|
||||
target_link_libraries(file_plugin PRIVATE util roctracer hsa-runtime64::hsa-runtime64 stdc++fs)
|
||||
target_link_libraries(file_plugin PRIVATE util roctracer amd_comgr hsa-runtime64::hsa-runtime64 stdc++fs amd_comgr)
|
||||
|
||||
install(TARGETS file_plugin LIBRARY
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <cxxabi.h>
|
||||
#include <amd_comgr/amd_comgr.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -103,14 +103,34 @@ std::string truncate_name(const std::string& name) {
|
||||
return name.substr(rend - rit, rit - rbeg);
|
||||
}
|
||||
|
||||
#define amd_comgr_(call) \
|
||||
do { \
|
||||
if (amd_comgr_status_t status = amd_comgr_##call; status != AMD_COMGR_STATUS_SUCCESS) { \
|
||||
const char* reason = ""; \
|
||||
amd_comgr_status_string(status, &reason); \
|
||||
fatal(#call " failed: %s", reason); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
// C++ symbol demangle
|
||||
std::string cxx_demangle(const std::string& symbol) {
|
||||
int status;
|
||||
char* demangled = abi::__cxa_demangle(symbol.c_str(), nullptr, nullptr, &status);
|
||||
if (status != 0) return symbol;
|
||||
std::string ret(demangled);
|
||||
free(demangled);
|
||||
return ret;
|
||||
amd_comgr_data_t mangled_data;
|
||||
amd_comgr_(create_data(AMD_COMGR_DATA_KIND_BYTES, &mangled_data));
|
||||
amd_comgr_(set_data(mangled_data, symbol.size(), symbol.data()));
|
||||
|
||||
amd_comgr_data_t demangled_data;
|
||||
amd_comgr_(demangle_symbol_name(mangled_data, &demangled_data));
|
||||
|
||||
size_t demangled_size = 0;
|
||||
amd_comgr_(get_data(demangled_data, &demangled_size, nullptr));
|
||||
|
||||
std::string demangled_str;
|
||||
demangled_str.resize(demangled_size);
|
||||
amd_comgr_(get_data(demangled_data, &demangled_size, demangled_str.data()));
|
||||
|
||||
amd_comgr_(release_data(mangled_data));
|
||||
amd_comgr_(release_data(demangled_data));
|
||||
return demangled_str;
|
||||
}
|
||||
|
||||
class file_plugin_t {
|
||||
|
||||
Reference in New Issue
Block a user