Fixed callback method for dl_iterate_phdr api which is called for each loaded shared object

Simplified the callback method. Also fixed the way, loaded shared object were getting appended into a string vector,
which was not being passed to this callback method.

Change-Id: I68661dd73f61a11c42fa92f670e8e7b6ffcb5711


[ROCm/ROCR-Runtime commit: 8751e65b79]
This commit is contained in:
Shweta Khatri
2022-10-21 13:46:17 -04:00
committed by David Yat Sin
parent 3268fe2a56
commit c236e10be6
@@ -204,24 +204,24 @@ void* GetExportAddress(LibHandle lib, std::string export_name) {
void CloseLib(LibHandle lib) { dlclose(*(void**)&lib); }
static int callback(struct dl_phdr_info* info, size_t size, void* data) {
if ((info) && (info->dlpi_name[0] != '\0')) {
std::vector<std::string>* loadedlib = (std::vector<std::string>*)data;
loadedlib->push_back(info->dlpi_name);
}
return 0;
}
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);
dl_iterate_phdr(callback, &names);
for(auto& name : names)
ret.push_back(LoadLib(name));
if (!names.empty()) {
for (auto& name : names) ret.push_back(LoadLib(name));
}
return ret;
}