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(); 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> cl::opt<bool>
NoHugePages("no-huge-pages", NoHugePages("no-huge-pages",
cl::desc("use regular size pages for code alignment"), 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. /// Handles DWO sections that can either be in .o, .dwo or .dwp files.
void BinaryContext::preprocessDWODebugInfo() { void BinaryContext::preprocessDWODebugInfo() {
// If DWP file exists use it to populate CU map. for (const std::unique_ptr<DWARFUnit> &CU : DwCtx->compile_units()) {
if (!opts::DWPPath.empty()) { DWARFUnit *const DwarfUnit = CU.get();
DWPContext = DwCtx->getDWOContext(opts::DWPPath.c_str()); if (llvm::Optional<uint64_t> DWOId = DwarfUnit->getDWOId()) {
if (!DWPContext) DWARFUnit *DWOCU = DwarfUnit->getNonSkeletonUnitDIE(false).getDwarfUnit();
report_error("DWP file not found.", if (!DWOCU->isDWOUnit()) {
std::make_error_code(std::errc::no_such_file_or_directory)); std::string DWOName = dwarf::toString(
for (const std::unique_ptr<DWARFUnit> &CU : DwCtx->compile_units()) { DwarfUnit->getUnitDIE().find(
DWARFUnit *DwarfUnit = CU.get(); {dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
if (llvm::Optional<uint64_t> DWOId = DwarfUnit->getDWOId()) { "");
DWARFCompileUnit *DWOCU = outs() << "BOLT-WARNING: Debug Fission: DWO debug information for "
DWPContext.get()->getDWOCompileUnitForHash(*DWOId); << DWOName
if (DWOCU) << " was not retrieved and won't be updated. Please check "
DWOCUs[*DWOId] = DWOCU; "relative path.\n";
} continue;
}
} 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;
} }
DWOCUs[*DWOId] = DWOCU;
} }
} }
} }

View File

@ -322,6 +322,11 @@ TrapOldCode("trap-old-code",
cl::Hidden, cl::Hidden,
cl::cat(BoltCategory)); 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> cl::opt<bool>
UpdateDebugSections("update-debug-sections", UpdateDebugSections("update-debug-sections",
cl::desc("update DWARF debug sections of the executable"), cl::desc("update DWARF debug sections of the executable"),
@ -474,8 +479,9 @@ RewriteInstance::RewriteInstance(ELFObjectFileBase *File, const int Argc,
BC = BinaryContext::createBinaryContext( BC = BinaryContext::createBinaryContext(
File, IsPIC, File, IsPIC,
DWARFContext::create( DWARFContext::create(
*File, DWARFContext::ProcessDebugRelocations::Process, nullptr, "", *File, DWARFContext::ProcessDebugRelocations::Process, nullptr,
WithColor::defaultErrorHandler, WithColor::defaultWarningHandler)); opts::DWPPathName, WithColor::defaultErrorHandler,
WithColor::defaultWarningHandler));
BAT = std::make_unique<BoltAddressTranslation>(*BC); BAT = std::make_unique<BoltAddressTranslation>(*BC);