Skip to content

Conversation

Jinjie-Huang
Copy link
Contributor

Currently in emitDWOBuilder(), when emitting Compile Units for DWO with dwarf version below 4, the Compile Unit information is obtained through SplitCU.getContext().dwo_compile_units(). This seems to assume that SplitCU is a DWO. However, if it is a DWP, it will at this point fetch and iterate over CUs that do not belong to the current DWO (and have not been registered), which will lead to a crash during emitUnit.

I may not be fully clear about some of the context, but it seems that a better approach here would be to align with the handling in dwarf5 and directly emit the current SplitCU. And this seems to both avoid the crash issue and be more efficient?

@llvmbot
Copy link
Member

llvmbot commented Aug 27, 2025

@llvm/pr-subscribers-bolt

Author: Jinjie Huang (Jinjie-Huang)

Changes

Currently in emitDWOBuilder(), when emitting Compile Units for DWO with dwarf version below 4, the Compile Unit information is obtained through SplitCU.getContext().dwo_compile_units(). This seems to assume that SplitCU is a DWO. However, if it is a DWP, it will at this point fetch and iterate over CUs that do not belong to the current DWO (and have not been registered), which will lead to a crash during emitUnit.

I may not be fully clear about some of the context, but it seems that a better approach here would be to align with the handling in dwarf5 and directly emit the current SplitCU. And this seems to both avoid the crash issue and be more efficient?


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

1 Files Affected:

  • (modified) bolt/lib/Rewrite/DWARFRewriter.cpp (+1-3)
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 0c1a1bac6c72e..6eefa5155298b 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -504,9 +504,7 @@ static void emitDWOBuilder(const std::string &DWOName,
     }
     emitUnit(DWODIEBuilder, *Streamer, SplitCU);
   } else {
-    for (std::unique_ptr<llvm::DWARFUnit> &CU :
-         SplitCU.getContext().dwo_compile_units())
-      emitUnit(DWODIEBuilder, *Streamer, *CU);
+    emitUnit(DWODIEBuilder, *Streamer, SplitCU);
 
     // emit debug_types sections for dwarf4
     for (DWARFUnit *CU : DWODIEBuilder.getDWARF4TUVector())

@Jinjie-Huang
Copy link
Contributor Author

@ayermolo @kazutakahirata PTAL, thanks!

@Jinjie-Huang Jinjie-Huang requested a review from Sockke August 28, 2025 03:46
@ayermolo
Copy link
Contributor

Umm yes, makes sense.
Can you add a test please.

@Jinjie-Huang Jinjie-Huang force-pushed the users/huangjinjie/fix_dwarf4_dwp_crash branch from a2de810 to 1405795 Compare September 2, 2025 12:48
@Jinjie-Huang
Copy link
Contributor Author

@ayermolo Thanks for review, and the test has been added.

@ayermolo
Copy link
Contributor

ayermolo commented Sep 2, 2025

Thanks for adding a test. Can you convert it to assembly test, and minimize assembly as much as possible, so it is more robust.

Copy link
Member

@paschalis-mpeis paschalis-mpeis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving support for split dwarf.
As this is generic, we’d welcome a test that runs on AArch64 too (if not much effort). :)

@Jinjie-Huang Jinjie-Huang force-pushed the users/huangjinjie/fix_dwarf4_dwp_crash branch from 1405795 to 2884b59 Compare September 3, 2025 13:15
@Jinjie-Huang
Copy link
Contributor Author

Jinjie-Huang commented Sep 3, 2025

I've modified the test to use the minimal assembly, and the test for AArch64 has also been added.

@Jinjie-Huang Jinjie-Huang force-pushed the users/huangjinjie/fix_dwarf4_dwp_crash branch from 8b89a0e to 5625046 Compare September 3, 2025 15:16
@Jinjie-Huang Jinjie-Huang force-pushed the users/huangjinjie/fix_dwarf4_dwp_crash branch from 5625046 to 4e82b92 Compare September 3, 2025 15:35
@@ -0,0 +1,450 @@
# RUN: rm -rf %t && mkdir -p %t && cd %t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add description of what this test does.
I think current convention is to use ## for Comments.

Copy link
Contributor Author

@Jinjie-Huang Jinjie-Huang Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. It seems we don't need to describe how the assembly comes via update_test_body.py, so I've also
removed this part for now.

@@ -0,0 +1,453 @@
# RUN: rm -rf %t && mkdir -p %t && cd %t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add description of what this test does.
I think current convention is to use ## for Comments.

echo '#--- callee.s'
clang++ --target=aarch64-unknown-unknown -c -g -gdwarf-4 -gsplit-dwarf -fdebug-compilation-dir=. -Xclang -split-dwarf-file -Xclang main.exe-callee.dwo -S callee.cpp -o -
#--- main.s
.file "main.cpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please minimize assembly. Example: #120103

@Jinjie-Huang Jinjie-Huang force-pushed the users/huangjinjie/fix_dwarf4_dwp_crash branch from 85d39ff to 6840dc8 Compare September 4, 2025 10:19
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.

4 participants