Skip to content

Conversation

@maksfb
Copy link
Contributor

@maksfb maksfb commented Dec 9, 2025

List all required missing DWO files and report a summary with recommendations on how to proceed.

List all required missing DWO files and report a summary with
recommendations on how to proceed.
@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2025

@llvm/pr-subscribers-bolt

Author: Maksim Panchenko (maksfb)

Changes

List all required missing DWO files and report a summary with recommendations on how to proceed.


Full diff: https://github.com/llvm/llvm-project/pull/171506.diff

2 Files Affected:

  • (modified) bolt/lib/Core/BinaryContext.cpp (+20-5)
  • (added) bolt/test/dwarf5-missing-dwo.c (+18)
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index 51bc867a839cf..824f7c7374443 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -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()) {
@@ -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 " << 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);
     }
 
@@ -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 {
diff --git a/bolt/test/dwarf5-missing-dwo.c b/bolt/test/dwarf5-missing-dwo.c
new file mode 100644
index 0000000000000..25de1a53aa5ac
--- /dev/null
+++ b/bolt/test/dwarf5-missing-dwo.c
@@ -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; }

@maksfb
Copy link
Contributor Author

maksfb commented Dec 9, 2025

Thanks for the review!

@maksfb maksfb merged commit dda715d into llvm:main Dec 9, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants