Fix to find MPI symbols from undefined symbols (#293)
* Fix to find MPI symbols from undefined symbols
* Moved condition checks before
* Fixing format
---------
Co-authored-by: Anuj Shukla <anujshuk@amd.com>
[ROCm/rocprofiler-systems commit: 67ec52b523]
Este commit está contenido en:
@@ -488,6 +488,77 @@ find_function(image_t* app_image, const std::string& _name, const strset_t& _ext
|
||||
return _func;
|
||||
}
|
||||
|
||||
//======================================================================================//
|
||||
//
|
||||
// Find undefined function symbols (external references) in the binary
|
||||
//
|
||||
symtab_symbol_t*
|
||||
find_undefined_function_symbol(image_t* app_image, const std::string& _name)
|
||||
{
|
||||
if(_name.empty()) return nullptr;
|
||||
|
||||
// Get all objects from the image
|
||||
BPatch_Vector<BPatch_object*> app_objects;
|
||||
app_image->getObjects(app_objects);
|
||||
|
||||
if(app_objects.empty())
|
||||
{
|
||||
verbprintf(3, "No objects found in image for symbol search\n");
|
||||
return nullptr;
|
||||
}
|
||||
// Search helper lambda for code reuse
|
||||
auto _find_symbol = [](SymTab::Symtab* symtab,
|
||||
const std::string& target_name) -> symtab_symbol_t* {
|
||||
if(!symtab) return nullptr;
|
||||
|
||||
std::vector<SymTab::Symbol*> all_symbols;
|
||||
if(!symtab->getAllSymbols(all_symbols)) return nullptr;
|
||||
|
||||
for(auto* symbol : all_symbols)
|
||||
{
|
||||
if(!symbol || symbol->getType() != SymTab::Symbol::ST_FUNCTION ||
|
||||
symbol->getRegion())
|
||||
continue;
|
||||
|
||||
// Try all possible symbol name representations
|
||||
std::string symbol_name = symbol->getPrettyName();
|
||||
if(symbol_name.empty()) symbol_name = symbol->getMangledName();
|
||||
if(symbol_name.empty()) symbol_name = symbol->getTypedName();
|
||||
|
||||
// Check for exact match and undefined function criteria
|
||||
if(symbol_name == target_name) return symbol;
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
// Search through each object
|
||||
for(auto* app_object : app_objects)
|
||||
{
|
||||
if(!app_object) continue;
|
||||
|
||||
std::string binary_path = app_object->name();
|
||||
// Open Symtab directly for comprehensive symbol access
|
||||
SymTab::Symtab* symtab = nullptr;
|
||||
if(!SymTab::Symtab::openFile(symtab, binary_path))
|
||||
{
|
||||
verbprintf(3, "Failed to open Symtab for: %s\n", binary_path.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Search for the primary symbol name
|
||||
auto* result = _find_symbol(symtab, _name);
|
||||
if(result)
|
||||
{
|
||||
verbprintf(1, "Found undefined function symbol: '%s' in %s\n", _name.c_str(),
|
||||
binary_path.c_str());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
verbprintf(1, "Undefined function symbol: '%s' ... not found\n", _name.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//======================================================================================//
|
||||
//
|
||||
// Get the realpath to this exe
|
||||
|
||||
@@ -360,6 +360,9 @@ insert_instr(address_space_t* mutatee, Tp traceFunc, procedure_loc_t traceLoc,
|
||||
procedure_t*
|
||||
find_function(image_t* appImage, const string_t& functionName, const strset_t& = {});
|
||||
|
||||
symtab_symbol_t*
|
||||
find_undefined_function_symbol(image_t* app_image, const std::string& _name);
|
||||
|
||||
void
|
||||
error_func_real(error_level_t level, int num, const char* const* params);
|
||||
|
||||
|
||||
+8
@@ -1721,6 +1721,14 @@ main(int argc, char** argv)
|
||||
use_mpi = true;
|
||||
break;
|
||||
}
|
||||
else if(find_undefined_function_symbol(app_image, itr) != nullptr)
|
||||
{
|
||||
verbprintf(0,
|
||||
"Found undefined symbol '%s' in '%s'. Enabling MPI support...\n",
|
||||
itr, _cmdv[0]);
|
||||
use_mpi = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Referencia en una nueva incidencia
Block a user