Skip to content

Commit dda715d

Browse files
authored
[BOLT][DWARF] Improve reporting on missing DWOs (#171506)
List all required missing DWO files and report a summary with recommendations on how to proceed.
1 parent 782f507 commit dda715d

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,9 @@ void BinaryContext::preprocessDebugInfo() {
18881888

18891889
preprocessDWODebugInfo();
18901890

1891+
// Check if required DWO files are missing.
1892+
uint64_t NumMissingDWOs = 0;
1893+
18911894
// Populate MCContext with DWARF files from all units.
18921895
StringRef GlobalPrefix = AsmInfo->getPrivateGlobalPrefix();
18931896
for (const std::unique_ptr<DWARFUnit> &CU : DwCtx->compile_units()) {
@@ -1909,19 +1912,23 @@ void BinaryContext::preprocessDebugInfo() {
19091912
std::optional<MD5::MD5Result> Checksum;
19101913
if (LineTable->Prologue.ContentTypes.HasMD5)
19111914
Checksum = LineTable->Prologue.FileNames[0].Checksum;
1912-
std::optional<const char *> Name =
1915+
const char *Name =
19131916
dwarf::toString(CU->getUnitDIE().find(dwarf::DW_AT_name), nullptr);
19141917
if (std::optional<uint64_t> DWOID = CU->getDWOId()) {
19151918
auto Iter = DWOCUs.find(*DWOID);
19161919
if (Iter == DWOCUs.end()) {
1917-
this->errs() << "BOLT-ERROR: DWO CU was not found for " << Name
1918-
<< '\n';
1919-
exit(1);
1920+
const char *DWOName =
1921+
dwarf::toString(CU->getUnitDIE().find(dwarf::DW_AT_dwo_name),
1922+
"<missing DW_AT_dwo_name>");
1923+
this->errs() << "BOLT-ERROR: unable to load " << DWOName
1924+
<< " for DWO_id 0x" << Twine::utohexstr(*DWOID) << '\n';
1925+
NumMissingDWOs++;
1926+
continue;
19201927
}
19211928
Name = dwarf::toString(
19221929
Iter->second->getUnitDIE().find(dwarf::DW_AT_name), nullptr);
19231930
}
1924-
BinaryLineTable.setRootFile(CU->getCompilationDir(), *Name, Checksum,
1931+
BinaryLineTable.setRootFile(CU->getCompilationDir(), Name, Checksum,
19251932
std::nullopt);
19261933
}
19271934

@@ -1956,6 +1963,14 @@ void BinaryContext::preprocessDebugInfo() {
19561963
DwarfVersion));
19571964
}
19581965
}
1966+
1967+
if (NumMissingDWOs) {
1968+
this->errs() << "BOLT-ERROR: " << NumMissingDWOs
1969+
<< " required DWO file(s) not found. Unable to update debug"
1970+
" info. Use --comp-dir-override to locate the file(s) or"
1971+
" --update-debug-sections=0 to remove debug info\n";
1972+
exit(1);
1973+
}
19591974
}
19601975

19611976
bool BinaryContext::shouldEmit(const BinaryFunction &Function) const {

bolt/test/dwarf5-missing-dwo.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Check that llvm-bolt correctly reports a missing DWO file while updating
2+
// debug info.
3+
//
4+
// RUN: %clang %cflags -g -dwarf5 -gsplit-dwarf=single -c %s -o %t.o
5+
// RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
6+
// RUN: rm %t.o
7+
// RUN: not llvm-bolt %t.exe -o %t.bolt --update-debug-sections \
8+
// RUN: 2>&1 | FileCheck %s -DDWO=%t.o
9+
//
10+
// Check that llvm-bolt succeeds on the same binary with disabled debug info
11+
// update.
12+
//
13+
// RUN: llvm-bolt %t.exe -o %t.bolt --update-debug-sections=0
14+
15+
// CHECK: BOLT-ERROR: unable to load [[DWO]]
16+
// CHECK-NEXT: BOLT-ERROR: 1 required DWO file(s) not found
17+
18+
int main() { return 0; }

0 commit comments

Comments
 (0)