summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2018-07-10 15:32:17 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2018-07-10 15:32:17 +0000
commit74dc40422c2c022c5762ff02147360afda8bf8d8 (patch)
tree62b843388e07ce9e2e3929a77467282073b345b5
parent7176a5d65f55dabbeebfc2cecfe247af722701cd (diff)
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336688 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/MC/MCObjectStreamer.h3
-rw-r--r--lib/MC/MCObjectStreamer.cpp2
-rw-r--r--tools/dsymutil/MachOUtils.cpp4
3 files changed, 7 insertions, 2 deletions
diff --git a/include/llvm/MC/MCObjectStreamer.h b/include/llvm/MC/MCObjectStreamer.h
index ac204de31a3..e21eb680f1c 100644
--- a/include/llvm/MC/MCObjectStreamer.h
+++ b/include/llvm/MC/MCObjectStreamer.h
@@ -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
diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp
index 8122af459b7..9fab8d835f8 100644
--- a/lib/MC/MCObjectStreamer.cpp
+++ b/lib/MC/MCObjectStreamer.cpp
@@ -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();
}
diff --git a/tools/dsymutil/MachOUtils.cpp b/tools/dsymutil/MachOUtils.cpp
index 5d70afdc9f7..eda530b810c 100644
--- a/tools/dsymutil/MachOUtils.cpp
+++ b/tools/dsymutil/MachOUtils.cpp
@@ -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);