Index: llvm/include/llvm/MC/MCObjectStreamer.h =================================================================== --- llvm/include/llvm/MC/MCObjectStreamer.h +++ llvm/include/llvm/MC/MCObjectStreamer.h @@ -89,6 +89,7 @@ public: void visitUsedSymbol(const MCSymbol &Sym) override; + void finishPendingLabels(); MCAssembler &getAssembler() { return *Assembler; } MCAssembler *getAssemblerPtr() override; Index: llvm/lib/MC/MCObjectStreamer.cpp =================================================================== --- llvm/lib/MC/MCObjectStreamer.cpp +++ llvm/lib/MC/MCObjectStreamer.cpp @@ -660,6 +660,8 @@ getAssembler().addFileName(Filename); } +void MCObjectStreamer::finishPendingLabels() { flushPendingLabels(nullptr); } + void MCObjectStreamer::FinishImpl() { // If we are generating dwarf for assembly source files dump out the sections. if (getContext().getGenDwarfForAssembly()) @@ -668,6 +670,6 @@ // Dump out the dwarf file & directory tables and line tables. MCDwarfLineTable::Emit(this, getAssembler().getDWARFLinetableParams()); - flushPendingLabels(nullptr); + finishPendingLabels(); getAssembler().Finish(); } Index: llvm/tools/dsymutil/MachOUtils.cpp =================================================================== --- llvm/tools/dsymutil/MachOUtils.cpp +++ llvm/tools/dsymutil/MachOUtils.cpp @@ -322,8 +322,10 @@ auto &ObjectStreamer = static_cast(MS); MCAssembler &MCAsm = ObjectStreamer.getAssembler(); auto &Writer = static_cast(MCAsm.getWriter()); - MCAsmLayout Layout(MCAsm); + // Finish but don't emit. + ObjectStreamer.finishPendingLabels(); + MCAsmLayout Layout(MCAsm); MCAsm.layout(Layout); BinaryHolder InputBinaryHolder(false);