diff --git a/llvm/include/llvm/MC/MCDwarf.h b/llvm/include/llvm/MC/MCDwarf.h --- a/llvm/include/llvm/MC/MCDwarf.h +++ b/llvm/include/llvm/MC/MCDwarf.h @@ -62,6 +62,9 @@ /// Emit the .debug_line_str section if appropriate. void emitSection(MCStreamer *MCOS); + + /// Returns finalized section. + SmallString<0> getFinalizedData(); }; /// Instances of this class represent the name of the dwarf .file directive and diff --git a/llvm/include/llvm/MC/StringTableBuilder.h b/llvm/include/llvm/MC/StringTableBuilder.h --- a/llvm/include/llvm/MC/StringTableBuilder.h +++ b/llvm/include/llvm/MC/StringTableBuilder.h @@ -85,7 +85,6 @@ void write(raw_ostream &OS) const; void write(uint8_t *Buf) const; -private: bool isFinalized() const { return Finalized; } }; diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp --- a/llvm/lib/MC/MCDwarf.cpp +++ b/llvm/lib/MC/MCDwarf.cpp @@ -334,12 +334,18 @@ // Switch to the .debug_line_str section. MCOS->SwitchSection( MCOS->getContext().getObjectFileInfo()->getDwarfLineStrSection()); + SmallString<0> Data = getFinalizedData(); + MCOS->emitBinaryData(Data.str()); +} + +SmallString<0> MCDwarfLineStr::getFinalizedData() { // Emit the strings without perturbing the offsets we used. - LineStrings.finalizeInOrder(); + if (!LineStrings.isFinalized()) + LineStrings.finalizeInOrder(); SmallString<0> Data; Data.resize(LineStrings.getSize()); LineStrings.write((uint8_t *)Data.data()); - MCOS->emitBinaryData(Data.str()); + return Data; } void MCDwarfLineStr::emitRef(MCStreamer *MCOS, StringRef Path) {