[PATCH] D115485: [DwarfDebug] Prioritise DWARF filename in debuginfo over MC Target Options

Andy Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 9 17:22:04 PST 2021


cbeuw created this revision.
cbeuw added a reviewer: dblaikie.
Herald added a subscriber: hiraditya.
cbeuw requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The value of splitDebugFilename in DICompileUnit is currently ignored when
emitting the dwo name into an object file. The path supplied in
MCOptions.SplitDwarfFile is used both as a real path to write the split
dwo content, and as the value of DW_AT_[GNU_]dwo_name emitted into the object
file.

Instead, the filename specified in DICompileUnit should be the one emitted so
long as it has been specified. Additionally, since MCOptions.SplitDwarfFile
points to a real path, this may lead to inconsistent compilation results when
doing remote/distributed builds.

MCOptions.SplitDwarfFile remains to be used as the real path to write the
dwo file, but splitDebugFilename in DICompileUnit is emitted when specified,
and otherwise falls back to emit MCOptions.SplitDwarfFile as-is


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115485

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/test/DebugInfo/X86/debug-macinfo-split-dwarf.ll
  llvm/test/DebugInfo/dwo-different-name.ll


Index: llvm/test/DebugInfo/dwo-different-name.ll
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/dwo-different-name.ll
@@ -0,0 +1,16 @@
+; RUN: %llc_dwarf %s -filetype=obj -o %t --split-dwarf-file from-mc-options.dwo
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
+; REQUIRES: default_triple, object-emission
+;
+; CHECK: DW_AT_GNU_dwo_name ("from-debuginfo.dwo")
+; CHECK-NOT: DW_AT_GNU_dwo_name ("from-mc-options.dwo")
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Clang", isOptimized: false, runtimeVersion: 2, splitDebugFilename: "from-debuginfo.dwo", emissionKind: FullDebug, enums: !2, globals: !2, retainedTypes: !5)
+!1 = !DIFile(filename: "<stdin>", directory: "/")
+!2 = !{}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{!6}
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
Index: llvm/test/DebugInfo/X86/debug-macinfo-split-dwarf.ll
===================================================================
--- llvm/test/DebugInfo/X86/debug-macinfo-split-dwarf.ll
+++ llvm/test/DebugInfo/X86/debug-macinfo-split-dwarf.ll
@@ -44,7 +44,7 @@
 !llvm.module.flags = !{!21, !22, !23}
 !llvm.ident = !{!24}
 
-!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "debug-macro-split-dwarf.dwo", emissionKind: FullDebug, enums: !2, macros: !3, nameTableKind: GNU)
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, macros: !3, nameTableKind: GNU)
 !1 = !DIFile(filename: "debug-macro-split-dwarf.c", directory: "/", checksumkind: CSK_MD5, checksum: "e74d0fa8f714535c1bac6da2ffbbd898")
 !2 = !{}
 !3 = !{!4, !14, !15, !16, !17, !18, !19, !20}
Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1247,10 +1247,12 @@
                                          ? dwarf::DW_AT_dwo_name
                                          : dwarf::DW_AT_GNU_dwo_name;
       finishUnitAttributes(TheCU.getCUNode(), TheCU);
-      TheCU.addString(TheCU.getUnitDie(), attrDWOName,
-                      Asm->TM.Options.MCOptions.SplitDwarfFile);
-      SkCU->addString(SkCU->getUnitDie(), attrDWOName,
-                      Asm->TM.Options.MCOptions.SplitDwarfFile);
+      StringRef embeddedDWOName = TheCU.getCUNode()->getSplitDebugFilename();
+      if (embeddedDWOName.empty()) {
+        embeddedDWOName = Asm->TM.Options.MCOptions.SplitDwarfFile;
+      }
+      TheCU.addString(TheCU.getUnitDie(), attrDWOName, embeddedDWOName);
+      SkCU->addString(SkCU->getUnitDie(), attrDWOName, embeddedDWOName);
       // Emit a unique identifier for this CU.
       uint64_t ID =
           DIEHash(Asm, &TheCU).computeCUSignature(DWOName, TheCU.getUnitDie());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115485.393344.patch
Type: text/x-patch
Size: 3097 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211210/8ea7f4fb/attachment.bin>


More information about the llvm-commits mailing list