OSDN Git Service

[MC] Add interface to finish pending labels.
authorJonas Devlieghere <jonas@devlieghere.com>
Tue, 10 Jul 2018 15:32:17 +0000 (15:32 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 10 Jul 2018 15:32:17 +0000 (15:32 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336688 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCObjectStreamer.h
lib/MC/MCObjectStreamer.cpp
tools/dsymutil/MachOUtils.cpp

index ac204de..e21eb68 100644 (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
index 8122af4..9fab8d8 100644 (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();
 }
index 5d70afd..eda530b 100644 (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);