diff --git a/src/program_state.cpp b/src/program_state.cpp index 3ad9285b8c..3eba84f12e 100644 --- a/src/program_state.cpp +++ b/src/program_state.cpp @@ -180,21 +180,29 @@ const unordered_map>>& code_object_blobs(bool reb static once_flag f; auto cons = [rebuild]() { + // names of shared libraries who .kernel sections already loaded + static unordered_set lib_names; static vector> blobs{code_object_blob_for_process()}; if (rebuild) { + r.clear(); blobs.clear(); - blobs.push_back(code_object_blob_for_process()); } dl_iterate_phdr( [](dl_phdr_info* info, std::size_t, void*) { elfio tmp; - if (tmp.load(info->dlpi_name)) { + if ((lib_names.find(info->dlpi_name) == lib_names.end()) && + (tmp.load(info->dlpi_name))) { const auto it = find_section_if( tmp, [](const section* x) { return x->get_name() == ".kernel"; }); - if (it) blobs.emplace_back(it->get_data(), it->get_data() + it->get_size()); + if (it) { + blobs.emplace_back( + it->get_data(), it->get_data() + it->get_size()); + // register the shared library as already loaded + lib_names.emplace(info->dlpi_name); + } } return 0; }, @@ -338,7 +346,8 @@ executables(bool rebuild) { // TODO: This leaks the hsa_executable_ts, it shoul static const auto accelerators = hc::accelerator::get_all(); if (rebuild) { - r.clear(); + // do NOT clear r so we reuse instances of hsa_executable_t + // created previously code_object_blobs(rebuild); }