Skip to content

Conversation

Jinjie-Huang
Copy link
Contributor

@Jinjie-Huang Jinjie-Huang commented Aug 21, 2025

Perhaps we can skip mapping the RangeListsWriters for those DWOs with a DWOId of 0, since currently "0" is considered invalid?

Btw, multiple DWOIds of 0 may lead to an assertion failure inside createRangeLocListAddressWriters("RangeLists writer for DWO unit already exists"). I hit this case when using the compiler built prior to this commit with -fsplit-dwarf-inlining enabled, which generates a large number of Compile Units with a DWO ID == 0. I'm not sure if there are other cases could also trigger this issue.

@llvmbot
Copy link
Member

llvmbot commented Aug 21, 2025

@llvm/pr-subscribers-bolt

Author: Jinjie Huang (Jinjie-Huang)

Changes

DWOs with a DWOId of 0 are considered invalid. Currently, createRangeLocListAddressWriters() is called before these invalid DWOs are skipped, which seems unnecessary. Perhaps we can check the DWOId beforehand?

BTW, this may lead to an assertion failure inside createRangeLocListAddressWriters("RangeLists writer for DWO unit already exists.), when a duplicate DWO ID of 0 is encountered. I hit this case when using the compiler built prior to this commit with -fsplit-dwarf-inlining enabled, which generates a large number of Compile Units with a DWO ID == 0. I'm not sure if other scenarios could also trigger this issue.


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

1 Files Affected:

  • (modified) bolt/lib/Rewrite/DWARFRewriter.cpp (+1-1)
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 0c1a1bac6c72e..e8f6189eb5a69 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -729,13 +729,13 @@ void DWARFRewriter::updateDebugInfo() {
     ThreadPoolInterface &ThreadPool =
         ParallelUtilities::getThreadPool(ThreadCount);
     for (DWARFUnit *CU : DIEBlder.getProcessedCUs()) {
-      createRangeLocListAddressWriters(*CU);
       std::optional<DWARFUnit *> SplitCU;
       std::optional<uint64_t> DWOId = CU->getDWOId();
       if (DWOId)
         SplitCU = BC.getDWOCU(*DWOId);
       if (!SplitCU)
         continue;
+      createRangeLocListAddressWriters(*CU);
       DebugAddrWriter &AddressWriter =
           *AddressWritersByCU[CU->getOffset()].get();
       DebugRangesSectionWriter &TempRangesSectionWriter =

@Jinjie-Huang Jinjie-Huang force-pushed the users/huangjinjie/bolt_dwoid_zero branch from 73d7ed2 to 7e2e637 Compare August 21, 2025 13:03
@Jinjie-Huang Jinjie-Huang force-pushed the users/huangjinjie/bolt_dwoid_zero branch from 7e2e637 to b6c3f3c Compare August 21, 2025 13:29
@Jinjie-Huang Jinjie-Huang changed the title [BOLT][DWARF] Avoid unnecessary work if DWO id is zero [BOLT][DWARF] Avoid work if DWO id is zero Aug 21, 2025
@Jinjie-Huang Jinjie-Huang changed the title [BOLT][DWARF] Avoid work if DWO id is zero [BOLT][DWARF] Avoid invalid work if DWO id is zero Aug 27, 2025
@ayermolo ayermolo self-assigned this Aug 27, 2025
@ayermolo
Copy link
Contributor

That sounds like a broken DWARF. Maybe better approach is to detect it and not to update debug information at all.

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