Rebase: [BOLT][DebugFission] Fix reading support for DWP

Summary:
Dived more in to DWARF APIs and llvm-symbolizer this is a more streamline way of doing it, and address base gets set properly.
Writing out dwo files with dwp input will be separate patch.

(cherry picked from FBD31361529)
This commit is contained in:
Rafael Auler 2021-06-16 09:52:03 -07:00 committed by Maksim Panchenko
parent a8b9319536
commit e485a9830b
2 changed files with 23 additions and 41 deletions

View File

@ -50,12 +50,6 @@ extern cl::opt<unsigned> ExecutionCountThreshold;
extern bool processAllFunctions();
static cl::opt<std::string>
DWPPath("dwp-path",
cl::desc("Path to DWP file. DWP file name must be same as "
"binary name with .dwp extension."),
cl::Hidden, cl::ZeroOrMore, cl::cat(BoltCategory));
cl::opt<bool>
NoHugePages("no-huge-pages",
cl::desc("use regular size pages for code alignment"),
@ -1467,40 +1461,22 @@ Optional<DWARFUnit *> BinaryContext::getDWOCU(uint64_t DWOId) {
/// Handles DWO sections that can either be in .o, .dwo or .dwp files.
void BinaryContext::preprocessDWODebugInfo() {
// If DWP file exists use it to populate CU map.
if (!opts::DWPPath.empty()) {
DWPContext = DwCtx->getDWOContext(opts::DWPPath.c_str());
if (!DWPContext)
report_error("DWP file not found.",
std::make_error_code(std::errc::no_such_file_or_directory));
for (const std::unique_ptr<DWARFUnit> &CU : DwCtx->compile_units()) {
DWARFUnit *DwarfUnit = CU.get();
if (llvm::Optional<uint64_t> DWOId = DwarfUnit->getDWOId()) {
DWARFCompileUnit *DWOCU =
DWPContext.get()->getDWOCompileUnitForHash(*DWOId);
if (DWOCU)
DWOCUs[*DWOId] = DWOCU;
}
}
} else {
for (const std::unique_ptr<DWARFUnit> &CU : DwCtx->compile_units()) {
DWARFUnit *const DwarfUnit = CU.get();
if (llvm::Optional<uint64_t> DWOId = DwarfUnit->getDWOId()) {
DWARFUnit *DWOCU =
DwarfUnit->getNonSkeletonUnitDIE(false).getDwarfUnit();
if (!DWOCU->isDWOUnit()) {
std::string DWOName = dwarf::toString(
DwarfUnit->getUnitDIE().find(
{dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
"");
outs() << "BOLT-WARNING: Debug Fission: DWO debug information for "
<< DWOName
<< " was not retrieved and won't be updated. Please check "
"relative path.\n";
continue;
}
DWOCUs[*DWOId] = DWOCU;
for (const std::unique_ptr<DWARFUnit> &CU : DwCtx->compile_units()) {
DWARFUnit *const DwarfUnit = CU.get();
if (llvm::Optional<uint64_t> DWOId = DwarfUnit->getDWOId()) {
DWARFUnit *DWOCU = DwarfUnit->getNonSkeletonUnitDIE(false).getDwarfUnit();
if (!DWOCU->isDWOUnit()) {
std::string DWOName = dwarf::toString(
DwarfUnit->getUnitDIE().find(
{dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
"");
outs() << "BOLT-WARNING: Debug Fission: DWO debug information for "
<< DWOName
<< " was not retrieved and won't be updated. Please check "
"relative path.\n";
continue;
}
DWOCUs[*DWOId] = DWOCU;
}
}
}

View File

@ -322,6 +322,11 @@ TrapOldCode("trap-old-code",
cl::Hidden,
cl::cat(BoltCategory));
static cl::opt<std::string> DWPPathName("dwp",
cl::desc("Path and name to DWP file."),
cl::Hidden, cl::ZeroOrMore,
cl::init(""), cl::cat(BoltCategory));
cl::opt<bool>
UpdateDebugSections("update-debug-sections",
cl::desc("update DWARF debug sections of the executable"),
@ -474,8 +479,9 @@ RewriteInstance::RewriteInstance(ELFObjectFileBase *File, const int Argc,
BC = BinaryContext::createBinaryContext(
File, IsPIC,
DWARFContext::create(
*File, DWARFContext::ProcessDebugRelocations::Process, nullptr, "",
WithColor::defaultErrorHandler, WithColor::defaultWarningHandler));
*File, DWARFContext::ProcessDebugRelocations::Process, nullptr,
opts::DWPPathName, WithColor::defaultErrorHandler,
WithColor::defaultWarningHandler));
BAT = std::make_unique<BoltAddressTranslation>(*BC);