[PATCH] D55281: debuginfo: Use symbol difference for CU length to simplify assembly reading/editing

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 10 14:48:06 PST 2018


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL348806: debuginfo: Use symbol difference for CU length to simplify assembly… (authored by dblaikie, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55281?vs=176659&id=177599#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55281/new/

https://reviews.llvm.org/D55281

Files:
  llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp
  llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
  llvm/trunk/test/DebugInfo/X86/sections_as_references.ll


Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -38,6 +38,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Target/TargetLoweringObjectFile.h"
+#include "llvm/Target/TargetMachine.h"
 #include <cassert>
 #include <cstdint>
 #include <string>
@@ -1553,7 +1554,17 @@
 void DwarfUnit::emitCommonHeader(bool UseOffsets, dwarf::UnitType UT) {
   // Emit size of content not including length itself
   Asm->OutStreamer->AddComment("Length of Unit");
-  Asm->emitInt32(getHeaderSize() + getUnitDie().getSize());
+  StringRef Prefix = isDwoUnit() ? "debug_info_dwo_" : "debug_info_";
+  MCSymbol *BeginLabel = Asm->createTempSymbol(Prefix + "start");
+  EndLabel = Asm->createTempSymbol(Prefix + "end");
+
+  // Use a label difference for the convenience of legible/easily modified
+  // assembly - except on NVPTX where label differences aren't supported.
+  if (Asm->TM.getTargetTriple().isNVPTX())
+    Asm->emitInt32(getHeaderSize() + getUnitDie().getSize());
+  else
+    Asm->EmitLabelDifference(EndLabel, BeginLabel, 4);
+  Asm->OutStreamer->EmitLabel(BeginLabel);
 
   Asm->OutStreamer->AddComment("DWARF version number");
   unsigned Version = DD->getDwarfVersion();
Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
===================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -48,6 +48,7 @@
 
   /// Target of Dwarf emission.
   AsmPrinter *Asm;
+  MCSymbol *EndLabel;
 
   // Holders for some common dwarf information.
   DwarfDebug *DD;
@@ -82,6 +83,7 @@
 public:
   // Accessors.
   AsmPrinter* getAsmPrinter() const { return Asm; }
+  MCSymbol *getEndLabel() const { return EndLabel; }
   uint16_t getLanguage() const { return CUNode->getSourceLanguage(); }
   const DICompileUnit *getCUNode() const { return CUNode; }
 
Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp
@@ -46,6 +46,8 @@
   TheU->emitHeader(UseOffsets);
 
   Asm->emitDwarfDIE(Die);
+
+  Asm->OutStreamer->EmitLabel(TheU->getEndLabel());
 }
 
 // Compute the size and offset for each DIE.
Index: llvm/trunk/test/DebugInfo/X86/sections_as_references.ll
===================================================================
--- llvm/trunk/test/DebugInfo/X86/sections_as_references.ll
+++ llvm/trunk/test/DebugInfo/X86/sections_as_references.ll
@@ -9,13 +9,19 @@
 ; CHECK-NOT: .L
 
 ; CHECK:      .section .debug_info
-; CHECK-NOT:  .L
-; CHECK:      .short 2             # DWARF version number
+; CHECK-NEXT: .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+; CHECK-NEXT: .Ldebug_info_start0:
+; CHECK-NEXT: .short 2             # DWARF version number
 ; CHECK-NOT:  .L
 ; CHECK:      .long .debug_abbrev  # Offset Into Abbrev. Section
 ; CHECK-NOT:  .L
 ; CHECK:      .long .debug_line    # DW_AT_stmt_list
 ; CHECK-NOT:  .L
+; CHECK:      .Ldebug_info_end0:
+; CHECK-NOT:  .L
+; CHECK:      .long .Ldebug_info_end1-.Ldebug_info_start1 # Length of Unit
+; CHECK-NEXT: .Ldebug_info_start1:
+; CHECK-NOT:  .L
 ; CHECK:      .long .debug_abbrev  # Offset Into Abbrev. Section
 ; CHECK-NOT:  .L
 ; CHECK:      .long .debug_line    # DW_AT_stmt_list
@@ -23,6 +29,7 @@
 ; CHECK:      .quad .debug_info+{{[0-9]+}} # DW_AT_type
 ; CHECK-NOT:  .L
 ; CHECK:      .byte 0              # End Of Children Mark
+; CHECK-NEXT: .Ldebug_info_end1:
 ; CHECK-NOT:  .L
 
 source_filename = "test/DebugInfo/X86/sections_as_references.ll"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55281.177599.patch
Type: text/x-patch
Size: 3819 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181210/17c6d089/attachment.bin>


More information about the llvm-commits mailing list