Index: llvm/include/llvm/MC/MCObjectStreamer.h =================================================================== --- llvm/include/llvm/MC/MCObjectStreamer.h +++ llvm/include/llvm/MC/MCObjectStreamer.h @@ -90,6 +90,9 @@ public: void visitUsedSymbol(const MCSymbol &Sym) override; + /// Create a dummy fragment to assign any pending labels. + void flushPendingLabels() { flushPendingLabels(nullptr); } + MCAssembler &getAssembler() { return *Assembler; } MCAssembler *getAssemblerPtr() override; /// \name MCStreamer Interface Index: llvm/lib/MC/MCObjectStreamer.cpp =================================================================== --- llvm/lib/MC/MCObjectStreamer.cpp +++ llvm/lib/MC/MCObjectStreamer.cpp @@ -668,6 +668,6 @@ // Dump out the dwarf file & directory tables and line tables. MCDwarfLineTable::Emit(this, getAssembler().getDWARFLinetableParams()); - flushPendingLabels(nullptr); + flushPendingLabels(); 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); + // Layout but don't emit. + ObjectStreamer.flushPendingLabels(); + MCAsmLayout Layout(MCAsm); MCAsm.layout(Layout); BinaryHolder InputBinaryHolder(false);