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. 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: 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"