Adding support for rocrtracer tools loading without environment variable

During hsa initializing stage, ROCr now searches all the loaded libraries
for a  symbol "HSA_AMD_TOOL_PRIORITY" and adds all those libraries to
the tools library init list.  Tools libraries listed in HSA_TOOLS_LIB
env variable are also loaded in the given order and take priority
over HSA_AMD_TOOL_PRIORITY.

Change-Id: I739af42bbd777c44a9152c11e17dd69979b65e82


[ROCm/ROCR-Runtime commit: e7fc301aa7]
This commit is contained in:
skhatri
2022-06-08 18:50:24 -04:00
کامیت شده توسط Sean Keely
والد 44278554de
کامیت 6b88a15fdc
4فایلهای تغییر یافته به همراه148 افزوده شده و 34 حذف شده
@@ -200,6 +200,35 @@ void* GetExportAddress(LibHandle lib, std::string export_name) {
void CloseLib(LibHandle lib) { dlclose(*(void**)&lib); }
std::vector<LibHandle> GetLoadedLibs() {
std::vector<LibHandle> ret;
std::vector<std::string> names;
auto callback = [&](dl_phdr_info* info) {
if(info->dlpi_name[0] != '\0')
names.push_back(info->dlpi_name);
};
typedef decltype(callback) call_t;
dl_iterate_phdr([](dl_phdr_info* info, size_t size, void* data){
auto& call = *(call_t*)data;
call(info);
return 0;
}, &callback);
for(auto& name : names)
ret.push_back(LoadLib(name));
return ret;
}
std::string GetLibraryName(LibHandle lib) {
link_map *map;
if(dlinfo(lib, RTLD_DI_LINKMAP, &map)!=0)
return "";
return map->l_name;
}
Mutex CreateMutex() {
pthread_mutex_t* mutex = new pthread_mutex_t;
pthread_mutex_init(mutex, NULL);
@@ -46,6 +46,7 @@
#define HSA_RUNTIME_CORE_UTIL_OS_H_
#include <string>
#include <vector>
#include "utils.h"
namespace rocr {
@@ -85,6 +86,15 @@ void* GetExportAddress(LibHandle lib, std::string export_name);
/// @param: lib(Input), library handle which will be unloaded.
void CloseLib(LibHandle lib);
/// @brief: Lists libraries in the process
/// @return: List of library handles
std::vector<LibHandle> GetLoadedLibs();
/// @brief: Returns the library's path name.
/// @param: lib(Input), libray handle
/// @return: Path name of library
std::string GetLibraryName(LibHandle lib);
/// @brief: Creates a mutex, will return NULL if failed.
/// @param: void.
/// @return: Mutex.
@@ -82,6 +82,15 @@ void* GetExportAddress(LibHandle lib, std::string export_name) {
void CloseLib(LibHandle lib) { FreeLibrary(*(::HMODULE*)&lib); }
std::vector<LibHandle> GetLoadedLibs() {
// Use EnumProcessModulesEx
static_assert(false, "Not implemented.");
}
std::string GetLibraryName(LibHandle lib) {
static_assert(false, "Not implemented.");
}
Mutex CreateMutex() { return CreateEvent(NULL, false, true, NULL); }
bool TryAcquireMutex(Mutex lock) {