[PATCH] D29407: AsmPrinter: Emit debug information sections lasst

Matthias Braun via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 1 11:18:14 PST 2017


MatzeB created this revision.
Herald added subscribers: mehdi_amini, mcrosier.

Attaching debug information should ideally not change the rest of the
binary. This works best when the debug information sections come last in
the file. See also the discussion in https://reviews.llvm.org/D29315 or
r197922 or rdar://15623193

This means that we should output the debug information after calling the
targets EmitEndOfAsmFile.

@Rafael: Could you please look at the changes to test/DebugInfo/X86/arange-and-stub.ll. This patch moves ".section        .data.DW.ref.foo,"aGw", at progbits,DW.ref.foo,comdat" from the end of the file to before the debug info which "CHECK: .data" catches unitentionally I think.


Repository:
  rL LLVM

https://reviews.llvm.org/D29407

Files:
  include/llvm/CodeGen/AsmPrinter.h
  lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  test/DebugInfo/X86/arange-and-stub.ll


Index: test/DebugInfo/X86/arange-and-stub.ll
===================================================================
--- test/DebugInfo/X86/arange-and-stub.ll
+++ test/DebugInfo/X86/arange-and-stub.ll
@@ -4,7 +4,7 @@
 ; CHECK-NOT: .section
 ; CHECK: .L_ZTId.DW.stub:
 
-; CHECK:  .data
+; CHECK:  .data{{$}}
 ; CHECK-NEXT: .Lsec_end0:
 
 source_filename = "test/DebugInfo/X86/arange-and-stub.ll"
Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -254,13 +254,14 @@
       Handlers.push_back(HandlerInfo(new CodeViewDebug(this),
                                      DbgTimerName, DbgTimerDescription,
                                      CodeViewLineTablesGroupName,
-                                     CodeViewLineTablesGroupDescription));
+                                     CodeViewLineTablesGroupDescription, true));
     }
     if (!EmitCodeView || MMI->getModule()->getDwarfVersion()) {
       DD = new DwarfDebug(this, &M);
       DD->beginModule();
       Handlers.push_back(HandlerInfo(DD, DbgTimerName, DbgTimerDescription,
-                                     DWARFGroupName, DWARFGroupDescription));
+                                     DWARFGroupName, DWARFGroupDescription,
+                                     true));
     }
   }
 
@@ -1198,15 +1199,14 @@
     }
   }
 
-  // Finalize debug and EH information.
+  // Called endModule on handlers (exception info).
   for (const HandlerInfo &HI : Handlers) {
+    if (HI.EmitLate)
+      continue;
     NamedRegionTimer T(HI.TimerName, HI.TimerDescription, HI.TimerGroupName,
                        HI.TimerGroupDescription, TimePassesIsEnabled);
     HI.Handler->endModule();
-    delete HI.Handler;
   }
-  Handlers.clear();
-  DD = nullptr;
 
   // If the target wants to know about weak references, print them all.
   if (MAI->getWeakRefDirective()) {
@@ -1282,6 +1282,20 @@
   // after everything else has gone out.
   EmitEndOfAsmFile(M);
 
+  // Finalize late handlers (debug info).
+  for (const HandlerInfo &HI : Handlers) {
+    if (HI.EmitLate) {
+      NamedRegionTimer T(HI.TimerName, HI.TimerDescription, HI.TimerGroupName,
+                         HI.TimerGroupDescription, TimePassesIsEnabled);
+      HI.Handler->endModule();
+    }
+    delete HI.Handler;
+  }
+  Handlers.clear();
+  DD = nullptr;
+
+  // Emit late handlers (debug info).
+
   MMI = nullptr;
 
   OutStreamer->Finish();
Index: include/llvm/CodeGen/AsmPrinter.h
===================================================================
--- include/llvm/CodeGen/AsmPrinter.h
+++ include/llvm/CodeGen/AsmPrinter.h
@@ -126,12 +126,13 @@
     const char *TimerDescription;
     const char *TimerGroupName;
     const char *TimerGroupDescription;
+    bool EmitLate; ///< Handlers endModule() is called after EmitEndOfAsmFile().
     HandlerInfo(AsmPrinterHandler *Handler, const char *TimerName,
                 const char *TimerDescription, const char *TimerGroupName,
-                const char *TimerGroupDescription)
+                const char *TimerGroupDescription, bool EmitLate = false)
         : Handler(Handler), TimerName(TimerName),
           TimerDescription(TimerDescription), TimerGroupName(TimerGroupName),
-          TimerGroupDescription(TimerGroupDescription) {}
+          TimerGroupDescription(TimerGroupDescription), EmitLate(EmitLate) {}
   };
   /// A vector of all debug/EH info emitters we should use. This vector
   /// maintains ownership of the emitters.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29407.86680.patch
Type: text/x-patch
Size: 3584 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170201/93ef6245/attachment.bin>


More information about the llvm-commits mailing list