[MC] Add interface to finish pending labels.

When manually finishing the object writer in dsymutil, it's possible
that there are pending labels that haven't been resolved. This results
in an assertion when the assembler tries to fixup a label that doesn't
have an address yet.

Differential revision: https://reviews.llvm.org/D49131

llvm-svn: 336688
This commit is contained in:
Jonas Devlieghere 2018-07-10 15:32:17 +00:00
parent 137d0a46b9
commit 714e840719
3 changed files with 7 additions and 2 deletions

View File

@ -90,6 +90,9 @@ protected:
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

View File

@ -671,6 +671,6 @@ void MCObjectStreamer::FinishImpl() {
// Dump out the dwarf file & directory tables and line tables.
MCDwarfLineTable::Emit(this, getAssembler().getDWARFLinetableParams());
flushPendingLabels(nullptr);
flushPendingLabels();
getAssembler().Finish();
}

View File

@ -322,8 +322,10 @@ bool generateDsymCompanion(const DebugMap &DM, MCStreamer &MS,
auto &ObjectStreamer = static_cast<MCObjectStreamer &>(MS);
MCAssembler &MCAsm = ObjectStreamer.getAssembler();
auto &Writer = static_cast<MachObjectWriter &>(MCAsm.getWriter());
MCAsmLayout Layout(MCAsm);
// Layout but don't emit.
ObjectStreamer.flushPendingLabels();
MCAsmLayout Layout(MCAsm);
MCAsm.layout(Layout);
BinaryHolder InputBinaryHolder(false);