-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLVM][DWARF] Add compilation directory and dwo name to TU in dwo section #74909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…tion This adds support to help LLDB when binary is built with split dwarf, has .debug_names accelerator table and DWP file. Final linked binary might have Type Units (TUs) with the same type signature in multiple compilation units. Although the signature is the same, TUs are not guranted to be bit identical. This is not a problem when they are in .o/.dwo files as LLDB can find them by looking at the right one based on DW_AT_comp_dir/DW_AT_name in skeleton CU. Once DWP is created, TUs are de-duplicated, and we need to know from which CU remaining one came from. This approach allows LLDB to figure it out, with minimal changes to the rest of the tooling. As would have been the case if .debug-tu-index section in DWP was modified.
@llvm/pr-subscribers-backend-webassembly @llvm/pr-subscribers-debuginfo Author: Alexander Yermolovich (ayermolo) ChangesThis adds support to help LLDB when binary is built with split dwarf, has This approach allows LLDB to figure it out, with minimal changes to the rest of Full diff: https://github.com/llvm/llvm-project/pull/74909.diff 3 Files Affected:
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index ab29020bf1d7b..1db295cd76536 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -3478,6 +3478,12 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
Ins.first->second = Signature;
if (useSplitDwarf()) {
+ if (getDwarfVersion() >= 5) {
+ if (!CompilationDir.empty())
+ NewTU.addString(UnitDie, dwarf::DW_AT_comp_dir, CompilationDir);
+ NewTU.addString(UnitDie, dwarf::DW_AT_dwo_name,
+ Asm->TM.Options.MCOptions.SplitDwarfFile);
+ }
MCSection *Section =
getDwarfVersion() <= 4
? Asm->getObjFileLowering().getDwarfTypesDWOSection()
diff --git a/llvm/test/CodeGen/X86/dwarf-headers.ll b/llvm/test/CodeGen/X86/dwarf-headers.ll
index 4c029de5dbfa1..3a3d9998659b2 100644
--- a/llvm/test/CodeGen/X86/dwarf-headers.ll
+++ b/llvm/test/CodeGen/X86/dwarf-headers.ll
@@ -75,14 +75,14 @@
; O-5: .debug_info contents:
; O-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_skeleton, abbr_offset
; O-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
-; O-5: 0x00000014: DW_TAG_skeleton_unit
+; O-5: 0x00000014: DW_TAG_skeleton_unit
;
; DWO-5: .debug_info.dwo contents:
; DWO-5: 0x00000000: Type Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_type, abbr_offset
; DWO-5: 0x00000018: DW_TAG_type_unit
-; DWO-5: 0x00000033: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
+; DWO-5: 0x00000035: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
; DWO-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
-; DWO-5: 0x00000047: DW_TAG_compile_unit
+; DWO-5: 0x00000049: DW_TAG_compile_unit
; ModuleID = 't.cpp'
diff --git a/llvm/test/DebugInfo/X86/debug-names-types.ll b/llvm/test/DebugInfo/X86/debug-names-types.ll
index d32691305d1c1..5617c2cafc6f0 100644
--- a/llvm/test/DebugInfo/X86/debug-names-types.ll
+++ b/llvm/test/DebugInfo/X86/debug-names-types.ll
@@ -1,5 +1,6 @@
; UNSUPPORTED: system-windows
; This checks that .debug_names can be generated with monolithic, and split-dwarf, when -fdebug-type-sections is enabled.
+; It also checks that TU in .debug_info.dwo has correct DW_AT_comp_dir and DW_AT_dwo_name.
; Generated with: clang++ main.cpp -g2 -gdwarf-5 -gpubnames -fdebug-types-section
; RUN: llc -mtriple=x86_64 -generate-type-units -dwarf-version=5 -filetype=obj %s -o %t
@@ -171,7 +172,7 @@
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV1]]
; CHECK-SPLIT-NEXT: Tag: DW_TAG_structure_type
; CHECK-SPLIT-NEXT: DW_IDX_type_unit: 0x00
-; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x0000001f
+; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000021
; CHECK-SPLIT-NEXT: }
; CHECK-SPLIT-NEXT: Entry @ 0xae {
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV]]
@@ -199,13 +200,36 @@
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV4]]
; CHECK-SPLIT-NEXT: Tag: DW_TAG_base_type
; CHECK-SPLIT-NEXT: DW_IDX_type_unit: 0x00
-; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000034
+; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000036
; CHECK-SPLIT-NEXT: }
; CHECK-SPLIT-NEXT: }
; CHECK-SPLIT-NEXT: ]
; CHECK-SPLIT-NEXT: }
+
+; RUN: llvm-dwarfdump -debug-info -r 0 %t > %tdebugInfo.txt
+; RUN: llvm-dwarfdump -debug-info -r 0 %t.mainTypes.dwo >> %tdebugInfo.txt
+; RUN: cat %tdebugInfo.txt | FileCheck %s --check-prefixes=CHECK-TYPE
+
+; CHECK-TYPE: DW_TAG_skeleton_unit
+; CHECK-TYPE-NEXT: DW_AT_stmt_list
+; CHECK-TYPE-NEXT: DW_AT_str_offsets_base
+; CHECK-TYPE-NEXT: DW_AT_comp_dir ("/typeSmall")
+; CHECK-TYPE-NEXT: DW_AT_dwo_name
+; CHECK-TYPE-SAME: debug-names-types.ll.tmp.mainTypes.dwo
+; CHECK-TYPE-NEXT: DW_AT_low_pc
+; CHECK-TYPE-NEXT: DW_AT_high_pc
+; CHECK-TYPE-NEXT: DW_AT_addr_base
+
+; CHECK-TYPE: .debug_info.dwo contents
+; CHECK-TYPE: DW_TAG_type_unit
+; CHECK-TYPE-NEXT: DW_AT_language
+; CHECK-TYPE-NEXT: DW_AT_comp_dir ("/typeSmall")
+; CHECK-TYPE-NEXT: DW_AT_dwo_name
+; CHECK-TYPE-SAME: debug-names-types.ll.tmp.mainTypes.dwo
+; CHECK-TYPE-NEXT: DW_AT_stmt_list
+
; ModuleID = 'main.cpp'
source_filename = "main.cpp"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
@llvm/pr-subscribers-backend-x86 Author: Alexander Yermolovich (ayermolo) ChangesThis adds support to help LLDB when binary is built with split dwarf, has This approach allows LLDB to figure it out, with minimal changes to the rest of Full diff: https://github.com/llvm/llvm-project/pull/74909.diff 3 Files Affected:
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index ab29020bf1d7b..1db295cd76536 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -3478,6 +3478,12 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
Ins.first->second = Signature;
if (useSplitDwarf()) {
+ if (getDwarfVersion() >= 5) {
+ if (!CompilationDir.empty())
+ NewTU.addString(UnitDie, dwarf::DW_AT_comp_dir, CompilationDir);
+ NewTU.addString(UnitDie, dwarf::DW_AT_dwo_name,
+ Asm->TM.Options.MCOptions.SplitDwarfFile);
+ }
MCSection *Section =
getDwarfVersion() <= 4
? Asm->getObjFileLowering().getDwarfTypesDWOSection()
diff --git a/llvm/test/CodeGen/X86/dwarf-headers.ll b/llvm/test/CodeGen/X86/dwarf-headers.ll
index 4c029de5dbfa1..3a3d9998659b2 100644
--- a/llvm/test/CodeGen/X86/dwarf-headers.ll
+++ b/llvm/test/CodeGen/X86/dwarf-headers.ll
@@ -75,14 +75,14 @@
; O-5: .debug_info contents:
; O-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_skeleton, abbr_offset
; O-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
-; O-5: 0x00000014: DW_TAG_skeleton_unit
+; O-5: 0x00000014: DW_TAG_skeleton_unit
;
; DWO-5: .debug_info.dwo contents:
; DWO-5: 0x00000000: Type Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_type, abbr_offset
; DWO-5: 0x00000018: DW_TAG_type_unit
-; DWO-5: 0x00000033: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
+; DWO-5: 0x00000035: Compile Unit: {{.*}} version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset
; DWO-5-SAME: DWO_id = 0xccd7e58ef8bf4aa6
-; DWO-5: 0x00000047: DW_TAG_compile_unit
+; DWO-5: 0x00000049: DW_TAG_compile_unit
; ModuleID = 't.cpp'
diff --git a/llvm/test/DebugInfo/X86/debug-names-types.ll b/llvm/test/DebugInfo/X86/debug-names-types.ll
index d32691305d1c1..5617c2cafc6f0 100644
--- a/llvm/test/DebugInfo/X86/debug-names-types.ll
+++ b/llvm/test/DebugInfo/X86/debug-names-types.ll
@@ -1,5 +1,6 @@
; UNSUPPORTED: system-windows
; This checks that .debug_names can be generated with monolithic, and split-dwarf, when -fdebug-type-sections is enabled.
+; It also checks that TU in .debug_info.dwo has correct DW_AT_comp_dir and DW_AT_dwo_name.
; Generated with: clang++ main.cpp -g2 -gdwarf-5 -gpubnames -fdebug-types-section
; RUN: llc -mtriple=x86_64 -generate-type-units -dwarf-version=5 -filetype=obj %s -o %t
@@ -171,7 +172,7 @@
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV1]]
; CHECK-SPLIT-NEXT: Tag: DW_TAG_structure_type
; CHECK-SPLIT-NEXT: DW_IDX_type_unit: 0x00
-; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x0000001f
+; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000021
; CHECK-SPLIT-NEXT: }
; CHECK-SPLIT-NEXT: Entry @ 0xae {
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV]]
@@ -199,13 +200,36 @@
; CHECK-SPLIT-NEXT: Abbrev: [[ABBREV4]]
; CHECK-SPLIT-NEXT: Tag: DW_TAG_base_type
; CHECK-SPLIT-NEXT: DW_IDX_type_unit: 0x00
-; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000034
+; CHECK-SPLIT-NEXT: DW_IDX_die_offset: 0x00000036
; CHECK-SPLIT-NEXT: }
; CHECK-SPLIT-NEXT: }
; CHECK-SPLIT-NEXT: ]
; CHECK-SPLIT-NEXT: }
+
+; RUN: llvm-dwarfdump -debug-info -r 0 %t > %tdebugInfo.txt
+; RUN: llvm-dwarfdump -debug-info -r 0 %t.mainTypes.dwo >> %tdebugInfo.txt
+; RUN: cat %tdebugInfo.txt | FileCheck %s --check-prefixes=CHECK-TYPE
+
+; CHECK-TYPE: DW_TAG_skeleton_unit
+; CHECK-TYPE-NEXT: DW_AT_stmt_list
+; CHECK-TYPE-NEXT: DW_AT_str_offsets_base
+; CHECK-TYPE-NEXT: DW_AT_comp_dir ("/typeSmall")
+; CHECK-TYPE-NEXT: DW_AT_dwo_name
+; CHECK-TYPE-SAME: debug-names-types.ll.tmp.mainTypes.dwo
+; CHECK-TYPE-NEXT: DW_AT_low_pc
+; CHECK-TYPE-NEXT: DW_AT_high_pc
+; CHECK-TYPE-NEXT: DW_AT_addr_base
+
+; CHECK-TYPE: .debug_info.dwo contents
+; CHECK-TYPE: DW_TAG_type_unit
+; CHECK-TYPE-NEXT: DW_AT_language
+; CHECK-TYPE-NEXT: DW_AT_comp_dir ("/typeSmall")
+; CHECK-TYPE-NEXT: DW_AT_dwo_name
+; CHECK-TYPE-SAME: debug-names-types.ll.tmp.mainTypes.dwo
+; CHECK-TYPE-NEXT: DW_AT_stmt_list
+
; ModuleID = 'main.cpp'
source_filename = "main.cpp"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
Looks OK. We could potentially do this in all DWARF versions, not just >= 5. (seems relatively harmless to do it in the v4 extension version of Split DWARF?) & could you get some measurements, especially .o file size (or more specifically, .o .debug_info size) for a clang build with this patch/without this patch? Just so we know what sort of growth to expect. |
We can, but then it just increases complexity, slightly, + more tests modified, probably, since then there will be else statement for GNU_dwo_name. OK, will see what increase in clang is. |
Ah, fair enough - yeah, if it wouldn't simplify the code, I wouldn't bother with it.
Thanks! |
From clang-18.dwp DIff 73039 bytes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me/at least worth using it to experiment, see if it works for lldb, etc.
Maybe a comment in the DwarfDebug source explaining what these attributes might be useful for?
I don't think LLDB has support yet for this, and tombstoning in linker yet. |
Yep yep - but I'm OK with tihs going in first. Sorry, didn't mean to request further testing/demonstrated value before it's committed - just that I think this is adequate to be committed, to facilitate further testing/development. |
* main: (5908 commits) [readtapi] Cleanup printing command line options (llvm#75106) [flang] Fix compilation error due to variable no being used (llvm#75210) [C API] Add getters and setters for fast-math flags on relevant instructions (llvm#75123) [libc++][CI] Tests the no RTTI configuration. (llvm#65518) [RemoveDIs] Fold variable into assert, it's only used once. NFC [RemoveDI] Handle DPValues in SROA (llvm#74089) [AArch64][GlobalISel] Test Pre-Commit for Look into array's element [mlir][tensor] Fix bug in `tensor.extract(tensor.from_elements)` folder (llvm#75109) [analyzer] Move alpha checker EnumCastOutOfRange to optin (llvm#67157) [RemoveDIs] Handle DPValues in replaceDbgDeclare (llvm#73507) [SHT_LLVM_BB_ADDR_MAP] Implements PGOAnalysisMap in Object and ObjectYAML with tests. [X86][GlobalISel] Add instruction selection for G_SELECT (llvm#70753) [AMDGPU] Remove unused function splitScalar64BitAddSub [LLVM][DWARF] Add compilation directory and dwo name to TU in dwo section (llvm#74909) [clang][Interp] Implement __builtin_ffs (llvm#72988) [RemoveDIs] Update ConvertDebugDeclareToDebugValue after llvm#72276 (llvm#73508) [libc][NFC] Reuse `FloatProperties` constant instead of creating new ones (llvm#75187) [RemoveDIs] Fix removeRedundantDdbgInstrs utils for dbg.declares (llvm#74102) Reapply "[RemoveDIs][NFC] Find DPValues using findDbgDeclares (llvm#73500)" [GitHub] Remove author association print from new-prs workflow ...
…tion (llvm#74909) This adds support to help LLDB when binary is built with split dwarf, has .debug_names accelerator table and DWP file. Final linked binary might have Type Units (TUs) with the same type signature in multiple compilation units. Although the signature is the same, TUs are not guranted to be bit identical. This is not a problem when they are in .o/.dwo files as LLDB can find them by looking at the right one based on DW_AT_comp_dir/DW_AT_name in skeleton CU. Once DWP is created, TUs are de-duplicated, and we need to know from which CU remaining one came from. This approach allows LLDB to figure it out, with minimal changes to the rest of the tooling. As would have been the case if .debug_tu_index section in DWP was modified.
This adds support to help LLDB when binary is built with split dwarf, has
.debug_names accelerator table and DWP file.
Final linked binary might have Type Units (TUs) with the same type signature in multiple
compilation units. Although the signature is the same, TUs are not guranted to
be bit identical. This is not a problem when they are in .o/.dwo files as LLDB
can find them by looking at the right one based on DW_AT_comp_dir/DW_AT_name in
skeleton CU. Once DWP is created, TUs are de-duplicated, and we need to know
from which CU remaining one came from.
This approach allows LLDB to figure it out, with minimal changes to the rest of
the tooling. As would have been the case if .debug-tu-index section in DWP was
modified.