aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCObjectStreamer.cpp
diff options
context:
space:
mode:
authorJames Y Knight <jyknight@google.com>2019-11-10 16:12:29 -0500
committerJames Y Knight <jyknight@google.com>2019-11-16 09:52:07 -0500
commitbf142fc43347d8a35a71f46f7dda7e2a0a992e0d (patch)
tree637c0d55792d11174365c5ffd6bd2d8f2d392990 /llvm/lib/MC/MCObjectStreamer.cpp
parent5987cc1bb5d5eb624135e76a6b3ade1aef94caf7 (diff)
downloadllvm-bf142fc43347d8a35a71f46f7dda7e2a0a992e0d.zip
llvm-bf142fc43347d8a35a71f46f7dda7e2a0a992e0d.tar.gz
llvm-bf142fc43347d8a35a71f46f7dda7e2a0a992e0d.tar.bz2
MCObjectStreamer: assign MCSymbols in the dummy fragment to offset 0.
In MCObjectStreamer, when there is no current fragment, initially symbols are created in a "pending" state and assigned to a dummy empty fragment. Previously, they were not being assigned an offset, and thus evaluateAbsolute would fail if trying to evaluate an expression 'a - b', where both 'a' and 'b' were in this pending state. Also slightly refactored the EmitLabel overload which takes an MCFragment for clarity. Fixes: https://llvm.org/PR41825 Differential Revision: https://reviews.llvm.org/D70062
Diffstat (limited to 'llvm/lib/MC/MCObjectStreamer.cpp')
-rw-r--r--llvm/lib/MC/MCObjectStreamer.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 83f6ab8..cc33810 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -243,18 +243,32 @@ void MCObjectStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
Symbol->setFragment(F);
Symbol->setOffset(F->getContents().size());
} else {
+ // Assign all pending labels to offset 0 within the dummy "pending"
+ // fragment. (They will all be reassigned to a real fragment in
+ // flushPendingLabels())
+ Symbol->setOffset(0);
PendingLabels.push_back(Symbol);
}
}
-void MCObjectStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc, MCFragment *F) {
+// Emit a label at a previously emitted fragment/offset position. This must be
+// within the currently-active section.
+void MCObjectStreamer::EmitLabelAtPos(MCSymbol *Symbol, SMLoc Loc,
+ MCFragment *F, uint64_t Offset) {
+ assert(F->getParent() == getCurrentSectionOnly());
+
MCStreamer::EmitLabel(Symbol, Loc);
getAssembler().registerSymbol(*Symbol);
auto *DF = dyn_cast_or_null<MCDataFragment>(F);
- if (DF)
+ Symbol->setOffset(Offset);
+ if (DF) {
Symbol->setFragment(F);
- else
+ } else {
+ assert(isa<MCDummyFragment>(F) &&
+ "F must either be an MCDataFragment or the pending MCDummyFragment");
+ assert(Offset == 0);
PendingLabels.push_back(Symbol);
+ }
}
void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value) {