Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,9 @@ void BinaryContext::preprocessDebugInfo() {

preprocessDWODebugInfo();

// Check if required DWO files are missing.
uint64_t NumMissingDWOs = 0;

// Populate MCContext with DWARF files from all units.
StringRef GlobalPrefix = AsmInfo->getPrivateGlobalPrefix();
for (const std::unique_ptr<DWARFUnit> &CU : DwCtx->compile_units()) {
Expand All @@ -1909,19 +1912,23 @@ void BinaryContext::preprocessDebugInfo() {
std::optional<MD5::MD5Result> Checksum;
if (LineTable->Prologue.ContentTypes.HasMD5)
Checksum = LineTable->Prologue.FileNames[0].Checksum;
std::optional<const char *> Name =
const char *Name =
dwarf::toString(CU->getUnitDIE().find(dwarf::DW_AT_name), nullptr);
if (std::optional<uint64_t> DWOID = CU->getDWOId()) {
auto Iter = DWOCUs.find(*DWOID);
if (Iter == DWOCUs.end()) {
this->errs() << "BOLT-ERROR: DWO CU was not found for " << Name
<< '\n';
exit(1);
const char *DWOName =
dwarf::toString(CU->getUnitDIE().find(dwarf::DW_AT_dwo_name),
"<missing DW_AT_dwo_name>");
this->errs() << "BOLT-ERROR: unable to load " << DWOName
<< " for DWO_id 0x" << Twine::utohexstr(*DWOID) << '\n';
NumMissingDWOs++;
continue;
}
Name = dwarf::toString(
Iter->second->getUnitDIE().find(dwarf::DW_AT_name), nullptr);
}
BinaryLineTable.setRootFile(CU->getCompilationDir(), *Name, Checksum,
BinaryLineTable.setRootFile(CU->getCompilationDir(), Name, Checksum,
std::nullopt);
}

Expand Down Expand Up @@ -1956,6 +1963,14 @@ void BinaryContext::preprocessDebugInfo() {
DwarfVersion));
}
}

if (NumMissingDWOs) {
this->errs() << "BOLT-ERROR: " << NumMissingDWOs
<< " required DWO file(s) not found. Unable to update debug"
" info. Use --comp-dir-override to locate the file(s) or"
" --update-debug-sections=0 to remove debug info\n";
exit(1);
}
}

bool BinaryContext::shouldEmit(const BinaryFunction &Function) const {
Expand Down
18 changes: 18 additions & 0 deletions bolt/test/dwarf5-missing-dwo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Check that llvm-bolt correctly reports a missing DWO file while updating
// debug info.
//
// RUN: %clang %cflags -g -dwarf5 -gsplit-dwarf=single -c %s -o %t.o
// RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
// RUN: rm %t.o
// RUN: not llvm-bolt %t.exe -o %t.bolt --update-debug-sections \
// RUN: 2>&1 | FileCheck %s -DDWO=%t.o
//
// Check that llvm-bolt succeeds on the same binary with disabled debug info
// update.
//
// RUN: llvm-bolt %t.exe -o %t.bolt --update-debug-sections=0

// CHECK: BOLT-ERROR: unable to load [[DWO]]
// CHECK-NEXT: BOLT-ERROR: 1 required DWO file(s) not found

int main() { return 0; }
Loading