[PATCH] D80945: [DebugInfo] Fix a fatal error originating from split-macro support

Sourabh Singh Tomar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 1 12:25:48 PDT 2020


SouraVX created this revision.
Herald added subscribers: llvm-commits, hiraditya, aprantl.
Herald added a project: LLVM.
SouraVX added reviewers: probinson, dblaikie.
SouraVX added a project: debug-info.
SouraVX added a parent revision: D78866: [DWARF5] Added support for emission of .debug_macro.dwo section.
SouraVX updated this revision to Diff 267697.
SouraVX added a comment.

Added corrected test case.


When generting DWARFv5 split dwarf macro info, `debug_line_offset` in
macro section header was pointing to `debug_line_start` symbol in `.debug_line`
section in primary binary resulting in relocation and subsequent
fatal error:

`fatal error: error in backend: A dwo section may not contain relocations`

In this case this should point to `debug_line_start` symbol in `debug_line.dwo`
section. LLVM does not emit `debug_line.dwo` section except for type
units.
As of now skip this field emission, since it is optional.

Link to previous discussion:
http://lists.llvm.org/pipermail/llvm-dev/2020-February/138861.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80945

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/test/DebugInfo/X86/debug-macro-dwo.ll


Index: llvm/test/DebugInfo/X86/debug-macro-dwo.ll
===================================================================
--- llvm/test/DebugInfo/X86/debug-macro-dwo.ll
+++ llvm/test/DebugInfo/X86/debug-macro-dwo.ll
@@ -9,7 +9,7 @@
 
 ; CHECK-LABEL:  .debug_macro.dwo contents:
 ; CHECK-NEXT: 0x00000000:
-; CHECK-NEXT: macro header: version = 0x0005, flags = 0x02
+; CHECK-NEXT: macro header: version = 0x0005, flags = 0x00
 ; CHECK-NEXT: DW_MACRO_start_file - lineno: 0 filenum: 0
 ; CHECK-NEXT:   DW_MACRO_start_file - lineno: 1 filenum: 1
 ; CHECK-NEXT:     DW_MACRO_define_strx - lineno: 1 macro: FOO 5
Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2894,18 +2894,25 @@
 #define HANDLE_MACRO_FLAG(ID, NAME) MACRO_FLAG_##NAME = ID,
 #include "llvm/BinaryFormat/Dwarf.def"
   };
+  // Flags `0` in macro section header implies DWARF32.
   uint8_t Flags = 0;
   Asm->OutStreamer->AddComment("Macro information version");
   Asm->emitInt16(5);
-  // We are setting Offset and line offset flags unconditionally here,
-  // since we're only supporting DWARF32 and line offset should be mostly
-  // present.
+  // We are setting DWARF32 and line offset flags unconditionally here
+  // for non-split case, since we're only supporting DWARF32 and line
+  // offset should be mostly present.
   // FIXME: Add support for DWARF64.
-  Flags |= MACRO_FLAG_DEBUG_LINE_OFFSET;
-  Asm->OutStreamer->AddComment("Flags: 32 bit, debug_line_offset present");
-  Asm->emitInt8(Flags);
-  Asm->OutStreamer->AddComment("debug_line_offset");
-  Asm->OutStreamer->emitSymbolValue(CU.getLineTableStartSym(), /*Size=*/4);
+  if (!DD.useSplitDwarf()) {
+    Flags |= MACRO_FLAG_DEBUG_LINE_OFFSET;
+    Asm->OutStreamer->AddComment("Flags: 32 bit, debug_line_offset present");
+    Asm->emitInt8(Flags);
+    Asm->OutStreamer->AddComment("debug_line_offset");
+    Asm->OutStreamer->emitSymbolValue(CU.getLineTableStartSym(), /*Size=*/4);
+  } else {
+    // FIXME: Add support for debug_ling_offset in .debug_macro.dwo.
+    Asm->OutStreamer->AddComment("Flags: 32 bit");
+    Asm->emitInt8(Flags);
+  }
 }
 
 void DwarfDebug::handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80945.267697.patch
Type: text/x-patch
Size: 2335 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200601/542d7f69/attachment.bin>


More information about the llvm-commits mailing list