blob: 6ec705bdddb73451aa0169e6df9847a7881b14ef [file] [log] [blame]
Daniel Dunbar8dc68ab2010-06-16 20:04:22 +00001//===- lib/MC/MCObjectStreamer.cpp - Object File MCStreamer Interface -----===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/MC/MCObjectStreamer.h"
Peter Collingbournedf39be62013-04-17 21:18:16 +000011#include "llvm/ADT/STLExtras.h"
Craig Topperf1d0f772012-03-26 06:58:25 +000012#include "llvm/MC/MCAsmBackend.h"
Daniel Dunbar8dc68ab2010-06-16 20:04:22 +000013#include "llvm/MC/MCAssembler.h"
Benjamin Kramer1abcd062010-07-29 17:48:06 +000014#include "llvm/MC/MCCodeEmitter.h"
Reid Klecknerdef731a2016-08-26 17:58:37 +000015#include "llvm/MC/MCCodeView.h"
Rafael Espindola89b93722010-12-10 07:39:47 +000016#include "llvm/MC/MCContext.h"
Rafael Espindolaf89671d2010-11-01 16:27:31 +000017#include "llvm/MC/MCDwarf.h"
Michael J. Spencer8067adc2010-07-19 06:13:10 +000018#include "llvm/MC/MCExpr.h"
Craig Topperf1d0f772012-03-26 06:58:25 +000019#include "llvm/MC/MCObjectWriter.h"
Serge Pavlovb02f1e92013-06-27 14:35:03 +000020#include "llvm/MC/MCSection.h"
Chandler Carruth974a4452014-01-07 11:48:04 +000021#include "llvm/MC/MCSymbol.h"
Craig Topperf1d0f772012-03-26 06:58:25 +000022#include "llvm/Support/ErrorHandling.h"
Petr Hosek27f2fb02016-05-28 05:57:48 +000023#include "llvm/Support/SourceMgr.h"
Daniel Dunbar8dc68ab2010-06-16 20:04:22 +000024using namespace llvm;
25
Lang Hames445025a2017-10-11 01:57:21 +000026MCObjectStreamer::MCObjectStreamer(MCContext &Context,
27 std::unique_ptr<MCAsmBackend> TAB,
Peter Collingbourne17a98142018-05-18 18:26:45 +000028 std::unique_ptr<MCObjectWriter> OW,
Lang Hames806f68b2017-10-11 23:34:47 +000029 std::unique_ptr<MCCodeEmitter> Emitter)
Nirav Dave92f209b2018-04-27 15:45:27 +000030 : MCStreamer(Context),
Peter Collingbourne17a98142018-05-18 18:26:45 +000031 Assembler(llvm::make_unique<MCAssembler>(
32 Context, std::move(TAB), std::move(Emitter), std::move(OW))),
Rafael Espindola41cea412015-05-27 20:52:32 +000033 EmitEHFrame(true), EmitDebugFrame(false) {}
Daniel Dunbar8dc68ab2010-06-16 20:04:22 +000034
Lang Hames806f68b2017-10-11 23:34:47 +000035MCObjectStreamer::~MCObjectStreamer() {}
Daniel Dunbar83b46712010-06-16 20:04:25 +000036
Nirav Dave4d344622018-04-30 19:22:40 +000037// AssemblerPtr is used for evaluation of expressions and causes
38// difference between asm and object outputs. Return nullptr to in
39// inline asm mode to limit divergence to assembly inputs.
40MCAssembler *MCObjectStreamer::getAssemblerPtr() {
41 if (getUseAssemblerInfoForParsing())
42 return Assembler.get();
43 return nullptr;
44}
45
Petr Hosek054db7d2015-04-12 23:42:25 +000046void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) {
Rafael Espindola4a2dc8f2015-10-03 00:57:12 +000047 if (PendingLabels.empty())
48 return;
49 if (!F) {
50 F = new MCDataFragment();
51 MCSection *CurSection = getCurrentSectionOnly();
52 CurSection->getFragmentList().insert(CurInsertionPoint, F);
53 F->setParent(CurSection);
Derek Schuffcdb105b2014-10-22 22:38:06 +000054 }
Rafael Espindola4a2dc8f2015-10-03 00:57:12 +000055 for (MCSymbol *Sym : PendingLabels) {
56 Sym->setFragment(F);
57 Sym->setOffset(FOffset);
58 }
59 PendingLabels.clear();
Derek Schuffcdb105b2014-10-22 22:38:06 +000060}
61
Vladimir Stefanovica7270f92018-11-21 16:28:39 +000062// When fixup's offset is a forward declared label, e.g.:
63//
64// .reloc 1f, R_MIPS_JALR, foo
65// 1: nop
66//
67// postpone adding it to Fixups vector until the label is defined and its offset
68// is known.
69void MCObjectStreamer::resolvePendingFixups() {
70 for (PendingMCFixup &PendingFixup : PendingFixups) {
71 if (!PendingFixup.Sym || PendingFixup.Sym->isUndefined ()) {
72 getContext().reportError(PendingFixup.Fixup.getLoc(),
73 "unresolved relocation offset");
74 continue;
75 }
76 flushPendingLabels(PendingFixup.DF, PendingFixup.DF->getContents().size());
77 PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset());
78 PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
79 }
80 PendingFixups.clear();
81}
82
Rafael Espindolad64f1702018-02-09 17:00:25 +000083// As a compile-time optimization, avoid allocating and evaluating an MCExpr
84// tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment.
Alex Bradburyff51b9f2018-08-16 11:26:37 +000085static Optional<uint64_t>
86absoluteSymbolDiff(MCAssembler &Asm, const MCSymbol *Hi, const MCSymbol *Lo) {
Reid Kleckner58e2c592018-03-15 21:24:04 +000087 assert(Hi && Lo);
Alex Bradburyff51b9f2018-08-16 11:26:37 +000088 if (Asm.getBackendPtr()->requiresDiffExpressionRelocations())
89 return None;
90
Rafael Espindolad64f1702018-02-09 17:00:25 +000091 if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
92 Hi->isVariable() || Lo->isVariable())
93 return None;
94
95 return Hi->getOffset() - Lo->getOffset();
96}
97
Rafael Espindola6c56dec2015-06-11 18:58:08 +000098void MCObjectStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi,
Duncan P. N. Exon Smith583dac82015-05-21 02:41:23 +000099 const MCSymbol *Lo,
100 unsigned Size) {
Alex Bradburyff51b9f2018-08-16 11:26:37 +0000101 if (Optional<uint64_t> Diff = absoluteSymbolDiff(getAssembler(), Hi, Lo)) {
Rafael Espindolad64f1702018-02-09 17:00:25 +0000102 EmitIntValue(*Diff, Size);
Rafael Espindola6c56dec2015-06-11 18:58:08 +0000103 return;
104 }
Rafael Espindolad64f1702018-02-09 17:00:25 +0000105 MCStreamer::emitAbsoluteSymbolDiff(Hi, Lo, Size);
106}
Duncan P. N. Exon Smith583dac82015-05-21 02:41:23 +0000107
Rafael Espindolad64f1702018-02-09 17:00:25 +0000108void MCObjectStreamer::emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
109 const MCSymbol *Lo) {
Alex Bradburyff51b9f2018-08-16 11:26:37 +0000110 if (Optional<uint64_t> Diff = absoluteSymbolDiff(getAssembler(), Hi, Lo)) {
Rafael Espindolad64f1702018-02-09 17:00:25 +0000111 EmitULEB128IntValue(*Diff);
112 return;
113 }
114 MCStreamer::emitAbsoluteSymbolDiffAsULEB128(Hi, Lo);
Duncan P. N. Exon Smith583dac82015-05-21 02:41:23 +0000115}
116
Pedro Artigas5399d252012-12-12 22:59:46 +0000117void MCObjectStreamer::reset() {
Pedro Artigas99cbdde2012-12-14 18:52:11 +0000118 if (Assembler)
119 Assembler->reset();
Rafael Espindola899cab62015-05-27 15:14:11 +0000120 CurInsertionPoint = MCSection::iterator();
Rafael Espindola23f2d7a2014-05-12 14:02:44 +0000121 EmitEHFrame = true;
122 EmitDebugFrame = false;
Derek Schuffcdb105b2014-10-22 22:38:06 +0000123 PendingLabels.clear();
Pedro Artigas5399d252012-12-12 22:59:46 +0000124 MCStreamer::reset();
125}
126
Rafael Espindola23f2d7a2014-05-12 14:02:44 +0000127void MCObjectStreamer::EmitFrames(MCAsmBackend *MAB) {
128 if (!getNumFrameInfos())
129 return;
130
131 if (EmitEHFrame)
132 MCDwarfFrameEmitter::Emit(*this, MAB, true);
133
134 if (EmitDebugFrame)
135 MCDwarfFrameEmitter::Emit(*this, MAB, false);
136}
137
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000138MCFragment *MCObjectStreamer::getCurrentFragment() const {
Rafael Espindola792e1582015-05-27 21:04:14 +0000139 assert(getCurrentSectionOnly() && "No current section!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000140
Rafael Espindola792e1582015-05-27 21:04:14 +0000141 if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
Duncan P. N. Exon Smith5d8fcb92015-10-10 00:13:11 +0000142 return &*std::prev(CurInsertionPoint);
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000143
Craig Topper4266ae82014-04-13 04:57:38 +0000144 return nullptr;
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000145}
146
Peter Smithe2b2a912018-06-06 09:40:06 +0000147static bool CanReuseDataFragment(const MCDataFragment &F,
148 const MCAssembler &Assembler,
149 const MCSubtargetInfo *STI) {
150 if (!F.hasInstructions())
151 return true;
Derek Schuff67144e32013-02-15 22:50:52 +0000152 // When bundling is enabled, we don't want to add data to a fragment that
153 // already has instructions (see MCELFStreamer::EmitInstToData for details)
Peter Smithe2b2a912018-06-06 09:40:06 +0000154 if (Assembler.isBundlingEnabled())
155 return Assembler.getRelaxAll();
156 // If the subtarget is changed mid fragment we start a new fragment to record
157 // the new STI.
158 return !STI || F.getSubtargetInfo() == STI;
159}
160
161MCDataFragment *
162MCObjectStreamer::getOrCreateDataFragment(const MCSubtargetInfo *STI) {
163 MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
164 if (!F || !CanReuseDataFragment(*F, *Assembler, STI)) {
David Blaikie22f32362014-04-10 21:53:47 +0000165 F = new MCDataFragment();
Peter Collingbournedf39be62013-04-17 21:18:16 +0000166 insert(F);
167 }
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000168 return F;
169}
170
Omer Paparo Bivas1be670d2017-10-24 06:16:03 +0000171MCPaddingFragment *MCObjectStreamer::getOrCreatePaddingFragment() {
172 MCPaddingFragment *F =
173 dyn_cast_or_null<MCPaddingFragment>(getCurrentFragment());
174 if (!F) {
175 F = new MCPaddingFragment();
176 insert(F);
177 }
178 return F;
179}
180
Rafael Espindolad4feaf82014-06-25 15:29:54 +0000181void MCObjectStreamer::visitUsedSymbol(const MCSymbol &Sym) {
Rafael Espindolaf00654b2015-05-29 20:21:02 +0000182 Assembler->registerSymbol(Sym);
Rafael Espindolad4feaf82014-06-25 15:29:54 +0000183}
184
Rafael Espindola23f2d7a2014-05-12 14:02:44 +0000185void MCObjectStreamer::EmitCFISections(bool EH, bool Debug) {
186 MCStreamer::EmitCFISections(EH, Debug);
187 EmitEHFrame = EH;
188 EmitDebugFrame = Debug;
189}
190
Kevin Enderby29c96f12014-04-22 17:27:29 +0000191void MCObjectStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
Craig Topper634763c2015-09-20 23:35:59 +0000192 SMLoc Loc) {
Rafael Espindola91c39aa2014-06-25 18:37:33 +0000193 MCStreamer::EmitValueImpl(Value, Size, Loc);
Rafael Espindola6f950232010-11-28 23:08:47 +0000194 MCDataFragment *DF = getOrCreateDataFragment();
Petr Hosekbc245c02015-06-27 01:54:17 +0000195 flushPendingLabels(DF, DF->getContents().size());
Rafael Espindola6f950232010-11-28 23:08:47 +0000196
Eric Christopherea40df32016-10-14 05:47:37 +0000197 MCDwarfLineEntry::Make(this, getCurrentSectionOnly());
Cameron Zwarich41b646c2013-05-25 21:56:53 +0000198
Rafael Espindola6f950232010-11-28 23:08:47 +0000199 // Avoid fixups when possible.
200 int64_t AbsValue;
Nirav Dave4d344622018-04-30 19:22:40 +0000201 if (Value->evaluateAsAbsolute(AbsValue, getAssemblerPtr())) {
Arnaud A. de Grandmaisond49739e02017-05-15 08:43:27 +0000202 if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
203 getContext().reportError(
204 Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
205 return;
206 }
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000207 EmitIntValue(AbsValue, Size);
Rafael Espindola2df042c2010-12-03 02:54:21 +0000208 return;
Rafael Espindola6f950232010-11-28 23:08:47 +0000209 }
Eli Bendersky64d9a322012-12-07 19:13:57 +0000210 DF->getFixups().push_back(
Jim Grosbach8b22e9c2015-05-15 19:13:05 +0000211 MCFixup::create(DF->getContents().size(), Value,
Kevin Enderby29c96f12014-04-22 17:27:29 +0000212 MCFixup::getKindForSize(Size, false), Loc));
Rafael Espindola2df042c2010-12-03 02:54:21 +0000213 DF->getContents().resize(DF->getContents().size() + Size, 0);
Rafael Espindola6f950232010-11-28 23:08:47 +0000214}
215
Reid Kleckner726d93c2017-10-10 00:57:36 +0000216MCSymbol *MCObjectStreamer::EmitCFILabel() {
217 MCSymbol *Label = getContext().createTempSymbol("cfi", true);
218 EmitLabel(Label);
219 return Label;
220}
221
Oliver Stannard25f4c352014-11-03 12:19:03 +0000222void MCObjectStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
223 // We need to create a local symbol to avoid relocations.
Jim Grosbach19696da2015-05-18 18:43:14 +0000224 Frame.Begin = getContext().createTempSymbol();
Oliver Stannard25f4c352014-11-03 12:19:03 +0000225 EmitLabel(Frame.Begin);
Rafael Espindola547be262012-01-07 22:42:19 +0000226}
227
Rafael Espindola1fe97372012-01-09 00:17:29 +0000228void MCObjectStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
Jim Grosbach19696da2015-05-18 18:43:14 +0000229 Frame.End = getContext().createTempSymbol();
Rafael Espindola49b52b32014-06-25 00:13:59 +0000230 EmitLabel(Frame.End);
Rafael Espindola1fe97372012-01-09 00:17:29 +0000231}
232
Rafael Espindola940b0c02017-02-10 15:13:12 +0000233void MCObjectStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
234 MCStreamer::EmitLabel(Symbol, Loc);
Rafael Espindolaea4afa92010-11-28 17:18:55 +0000235
Rafael Espindolaf00654b2015-05-29 20:21:02 +0000236 getAssembler().registerSymbol(*Symbol);
Derek Schuffcdb105b2014-10-22 22:38:06 +0000237
238 // If there is a current fragment, mark the symbol as pointing into it.
239 // Otherwise queue the label and set its fragment pointer when we emit the
240 // next fragment.
Petr Hosek054db7d2015-04-12 23:42:25 +0000241 auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
242 if (F && !(getAssembler().isBundlingEnabled() &&
243 getAssembler().getRelaxAll())) {
Rafael Espindolacfac75a2015-05-29 21:45:01 +0000244 Symbol->setFragment(F);
Rafael Espindola82fdcc02015-05-29 17:48:04 +0000245 Symbol->setOffset(F->getContents().size());
Derek Schuffcdb105b2014-10-22 22:38:06 +0000246 } else {
Rafael Espindola052a7be2015-05-29 17:41:59 +0000247 PendingLabels.push_back(Symbol);
Derek Schuffcdb105b2014-10-22 22:38:06 +0000248 }
Rafael Espindolaea4afa92010-11-28 17:18:55 +0000249}
250
Weiming Zhaoc4d38012017-04-03 21:50:04 +0000251void MCObjectStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc, MCFragment *F) {
252 MCStreamer::EmitLabel(Symbol, Loc);
253 getAssembler().registerSymbol(*Symbol);
254 auto *DF = dyn_cast_or_null<MCDataFragment>(F);
255 if (DF)
256 Symbol->setFragment(F);
257 else
258 PendingLabels.push_back(Symbol);
259}
260
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000261void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value) {
Rafael Espindola660b5fc2010-12-03 01:19:49 +0000262 int64_t IntValue;
Nirav Dave4d344622018-04-30 19:22:40 +0000263 if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000264 EmitULEB128IntValue(IntValue);
Rafael Espindola660b5fc2010-12-03 01:19:49 +0000265 return;
266 }
Peter Collingbournedf39be62013-04-17 21:18:16 +0000267 insert(new MCLEBFragment(*Value, false));
Rafael Espindola3ff57092010-11-02 17:22:24 +0000268}
269
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000270void MCObjectStreamer::EmitSLEB128Value(const MCExpr *Value) {
Rafael Espindola660b5fc2010-12-03 01:19:49 +0000271 int64_t IntValue;
Nirav Dave4d344622018-04-30 19:22:40 +0000272 if (Value->evaluateAsAbsolute(IntValue, getAssemblerPtr())) {
Rafael Espindolae8cfbd82011-04-21 23:39:26 +0000273 EmitSLEB128IntValue(IntValue);
Rafael Espindola660b5fc2010-12-03 01:19:49 +0000274 return;
275 }
Peter Collingbournedf39be62013-04-17 21:18:16 +0000276 insert(new MCLEBFragment(*Value, true));
Rafael Espindola3ff57092010-11-02 17:22:24 +0000277}
278
Rafael Espindola484291c2010-11-01 14:28:48 +0000279void MCObjectStreamer::EmitWeakReference(MCSymbol *Alias,
280 const MCSymbol *Symbol) {
281 report_fatal_error("This file format doesn't support weak aliases.");
282}
283
Rafael Espindola75219642015-05-21 19:20:38 +0000284void MCObjectStreamer::ChangeSection(MCSection *Section,
Peter Collingbournedf39be62013-04-17 21:18:16 +0000285 const MCExpr *Subsection) {
Rafael Espindolad80979b2015-03-20 20:00:01 +0000286 changeSectionImpl(Section, Subsection);
287}
288
Rafael Espindola75219642015-05-21 19:20:38 +0000289bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
Rafael Espindolad80979b2015-03-20 20:00:01 +0000290 const MCExpr *Subsection) {
Daniel Dunbar83b46712010-06-16 20:04:25 +0000291 assert(Section && "Cannot switch to a null section!");
Derek Schuffcdb105b2014-10-22 22:38:06 +0000292 flushPendingLabels(nullptr);
David Blaikiebd97f5e2017-03-16 00:52:18 +0000293 getContext().clearDwarfLocSeen();
Daniel Dunbar83b46712010-06-16 20:04:25 +0000294
Rafael Espindolab14ebd62015-05-26 15:07:25 +0000295 bool Created = getAssembler().registerSection(*Section);
Peter Collingbournedf39be62013-04-17 21:18:16 +0000296
297 int64_t IntSubsection = 0;
298 if (Subsection &&
Nirav Dave4d344622018-04-30 19:22:40 +0000299 !Subsection->evaluateAsAbsolute(IntSubsection, getAssemblerPtr()))
Peter Collingbournedf39be62013-04-17 21:18:16 +0000300 report_fatal_error("Cannot evaluate subsection number");
301 if (IntSubsection < 0 || IntSubsection > 8192)
302 report_fatal_error("Subsection number out of range");
303 CurInsertionPoint =
Rafael Espindola41cea412015-05-27 20:52:32 +0000304 Section->getSubsectionInsertionPoint(unsigned(IntSubsection));
Rafael Espindolad80979b2015-03-20 20:00:01 +0000305 return Created;
Daniel Dunbar83b46712010-06-16 20:04:25 +0000306}
307
Eli Benderskyef76b272012-12-07 17:42:41 +0000308void MCObjectStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
Rafael Espindolaf00654b2015-05-29 20:21:02 +0000309 getAssembler().registerSymbol(*Symbol);
Zoran Jovanovicb71fd202014-03-20 09:44:49 +0000310 MCStreamer::EmitAssignment(Symbol, Value);
Eli Benderskyef76b272012-12-07 17:42:41 +0000311}
312
Rafael Espindola712c27f2015-05-25 18:34:26 +0000313bool MCObjectStreamer::mayHaveInstructions(MCSection &Sec) const {
314 return Sec.hasInstructions();
315}
316
Rafael Espindola91c39aa2014-06-25 18:37:33 +0000317void MCObjectStreamer::EmitInstruction(const MCInst &Inst,
Andrew V. Tischenko37965612017-04-14 07:44:23 +0000318 const MCSubtargetInfo &STI, bool) {
Omer Paparo Bivas1be670d2017-10-24 06:16:03 +0000319 getAssembler().getBackend().handleCodePaddingInstructionBegin(Inst);
320 EmitInstructionImpl(Inst, STI);
321 getAssembler().getBackend().handleCodePaddingInstructionEnd(Inst);
322}
323
324void MCObjectStreamer::EmitInstructionImpl(const MCInst &Inst,
325 const MCSubtargetInfo &STI) {
Rafael Espindola91c39aa2014-06-25 18:37:33 +0000326 MCStreamer::EmitInstruction(Inst, STI);
Rafael Espindolaf89671d2010-11-01 16:27:31 +0000327
Rafael Espindola792e1582015-05-27 21:04:14 +0000328 MCSection *Sec = getCurrentSectionOnly();
Rafael Espindola7ff8c5c2015-05-26 14:48:11 +0000329 Sec->setHasInstructions(true);
Rafael Espindolaf89671d2010-11-01 16:27:31 +0000330
331 // Now that a machine instruction has been assembled into this section, make
332 // a line entry for any .loc directive that has been seen.
Eric Christopherea40df32016-10-14 05:47:37 +0000333 MCDwarfLineEntry::Make(this, getCurrentSectionOnly());
Rafael Espindolaf89671d2010-11-01 16:27:31 +0000334
335 // If this instruction doesn't need relaxation, just emit it as data.
Eli Bendersky4766ef42012-12-20 19:05:53 +0000336 MCAssembler &Assembler = getAssembler();
Peter Smithe2b2a912018-06-06 09:40:06 +0000337 if (!Assembler.getBackend().mayNeedRelaxation(Inst, STI)) {
David Woodhoused5d381b2014-01-28 23:12:49 +0000338 EmitInstToData(Inst, STI);
Rafael Espindolaf89671d2010-11-01 16:27:31 +0000339 return;
340 }
341
Eli Bendersky4766ef42012-12-20 19:05:53 +0000342 // Otherwise, relax and emit it as data if either:
343 // - The RelaxAll flag was passed
344 // - Bundling is enabled and this instruction is inside a bundle-locked
345 // group. We want to emit all such instructions into the same data
346 // fragment.
347 if (Assembler.getRelaxAll() ||
Rafael Espindola7ff8c5c2015-05-26 14:48:11 +0000348 (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
Rafael Espindolaf89671d2010-11-01 16:27:31 +0000349 MCInst Relaxed;
Nirav Dave6b00c9f2016-07-11 14:23:53 +0000350 getAssembler().getBackend().relaxInstruction(Inst, STI, Relaxed);
Peter Smithe2b2a912018-06-06 09:40:06 +0000351 while (getAssembler().getBackend().mayNeedRelaxation(Relaxed, STI))
Nirav Dave6b00c9f2016-07-11 14:23:53 +0000352 getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed);
David Woodhoused5d381b2014-01-28 23:12:49 +0000353 EmitInstToData(Relaxed, STI);
Rafael Espindolaf89671d2010-11-01 16:27:31 +0000354 return;
355 }
356
357 // Otherwise emit to a separate fragment.
David Woodhoused5d381b2014-01-28 23:12:49 +0000358 EmitInstToFragment(Inst, STI);
Rafael Espindolaf89671d2010-11-01 16:27:31 +0000359}
360
David Woodhoused5d381b2014-01-28 23:12:49 +0000361void MCObjectStreamer::EmitInstToFragment(const MCInst &Inst,
362 const MCSubtargetInfo &STI) {
Petr Hosek054db7d2015-04-12 23:42:25 +0000363 if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
364 llvm_unreachable("All instructions should have already been relaxed");
365
Eli Bendersky4766ef42012-12-20 19:05:53 +0000366 // Always create a new, separate fragment here, because its size can change
367 // during relaxation.
David Woodhouse41c8ba92014-01-28 23:12:53 +0000368 MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
Peter Collingbournedf39be62013-04-17 21:18:16 +0000369 insert(IF);
Rafael Espindoladedb0452010-12-02 05:44:06 +0000370
Eli Friedman50ebe532011-04-18 20:54:46 +0000371 SmallString<128> Code;
372 raw_svector_ostream VecOS(Code);
Jim Grosbach251a66e2015-05-15 19:13:16 +0000373 getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
David Woodhouse2ddea4b2014-01-28 23:13:07 +0000374 STI);
Eli Bendersky64d9a322012-12-07 19:13:57 +0000375 IF->getContents().append(Code.begin(), Code.end());
Rafael Espindoladedb0452010-12-02 05:44:06 +0000376}
377
Matt Beaumont-Gayf7870852013-02-15 23:12:33 +0000378#ifndef NDEBUG
Craig Topper4172a8a2013-07-16 01:17:10 +0000379static const char *const BundlingNotImplementedMsg =
Eli Bendersky4766ef42012-12-20 19:05:53 +0000380 "Aligned bundling is not implemented for this object format";
Matt Beaumont-Gayf7870852013-02-15 23:12:33 +0000381#endif
Eli Bendersky4766ef42012-12-20 19:05:53 +0000382
383void MCObjectStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
384 llvm_unreachable(BundlingNotImplementedMsg);
385}
386
Eli Bendersky6c1d4972013-01-07 21:51:08 +0000387void MCObjectStreamer::EmitBundleLock(bool AlignToEnd) {
Eli Bendersky4766ef42012-12-20 19:05:53 +0000388 llvm_unreachable(BundlingNotImplementedMsg);
389}
390
391void MCObjectStreamer::EmitBundleUnlock() {
392 llvm_unreachable(BundlingNotImplementedMsg);
393}
394
Ulrich Weigand4df4bcc2013-06-19 21:27:27 +0000395void MCObjectStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
396 unsigned Column, unsigned Flags,
397 unsigned Isa,
398 unsigned Discriminator,
399 StringRef FileName) {
400 // In case we see two .loc directives in a row, make sure the
401 // first one gets a line entry.
Eric Christopherea40df32016-10-14 05:47:37 +0000402 MCDwarfLineEntry::Make(this, getCurrentSectionOnly());
Ulrich Weigand4df4bcc2013-06-19 21:27:27 +0000403
404 this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
405 Isa, Discriminator, FileName);
406}
407
Rafael Espindola305a51f2014-08-15 14:31:47 +0000408static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
409 const MCSymbol *B) {
410 MCContext &Context = OS.getContext();
411 MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
Jim Grosbach586c0042015-05-30 01:25:56 +0000412 const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
413 const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
Rafael Espindola305a51f2014-08-15 14:31:47 +0000414 const MCExpr *AddrDelta =
Jim Grosbach586c0042015-05-30 01:25:56 +0000415 MCBinaryExpr::create(MCBinaryExpr::Sub, ARef, BRef, Context);
Rafael Espindola305a51f2014-08-15 14:31:47 +0000416 return AddrDelta;
417}
418
Frederic Riss796478f2015-08-07 15:14:08 +0000419static void emitDwarfSetLineAddr(MCObjectStreamer &OS,
420 MCDwarfLineTableParams Params,
421 int64_t LineDelta, const MCSymbol *Label,
422 int PointerSize) {
Rafael Espindola4d15a242014-08-15 14:43:02 +0000423 // emit the sequence to set the address
424 OS.EmitIntValue(dwarf::DW_LNS_extended_op, 1);
425 OS.EmitULEB128IntValue(PointerSize + 1);
426 OS.EmitIntValue(dwarf::DW_LNE_set_address, 1);
427 OS.EmitSymbolValue(Label, PointerSize);
428
429 // emit the sequence for the LineDelta (from 1) and a zero address delta.
Frederic Riss796478f2015-08-07 15:14:08 +0000430 MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
Rafael Espindola4d15a242014-08-15 14:43:02 +0000431}
432
Rafael Espindola32a006e2010-12-03 00:55:40 +0000433void MCObjectStreamer::EmitDwarfAdvanceLineAddr(int64_t LineDelta,
434 const MCSymbol *LastLabel,
Evan Cheng672b93a2011-07-14 05:43:07 +0000435 const MCSymbol *Label,
436 unsigned PointerSize) {
Rafael Espindola32a006e2010-12-03 00:55:40 +0000437 if (!LastLabel) {
Frederic Riss796478f2015-08-07 15:14:08 +0000438 emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
439 Label, PointerSize);
Rafael Espindola32a006e2010-12-03 00:55:40 +0000440 return;
441 }
Rafael Espindola305a51f2014-08-15 14:31:47 +0000442 const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
Rafael Espindola32a006e2010-12-03 00:55:40 +0000443 int64_t Res;
Nirav Dave4d344622018-04-30 19:22:40 +0000444 if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
Frederic Riss796478f2015-08-07 15:14:08 +0000445 MCDwarfLineAddr::Emit(this, Assembler->getDWARFLinetableParams(), LineDelta,
446 Res);
Rafael Espindola32a006e2010-12-03 00:55:40 +0000447 return;
448 }
Peter Collingbournedf39be62013-04-17 21:18:16 +0000449 insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
Rafael Espindola32a006e2010-12-03 00:55:40 +0000450}
451
Rafael Espindola245a1e22010-12-28 05:39:27 +0000452void MCObjectStreamer::EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
453 const MCSymbol *Label) {
Rafael Espindola305a51f2014-08-15 14:31:47 +0000454 const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
Rafael Espindola245a1e22010-12-28 05:39:27 +0000455 int64_t Res;
Nirav Dave4d344622018-04-30 19:22:40 +0000456 if (AddrDelta->evaluateAsAbsolute(Res, getAssemblerPtr())) {
Rafael Espindola245a1e22010-12-28 05:39:27 +0000457 MCDwarfFrameEmitter::EmitAdvanceLoc(*this, Res);
458 return;
459 }
Peter Collingbournedf39be62013-04-17 21:18:16 +0000460 insert(new MCDwarfCallFrameFragment(*AddrDelta));
Rafael Espindola245a1e22010-12-28 05:39:27 +0000461}
462
Reid Kleckner1689efb2016-01-29 00:49:42 +0000463void MCObjectStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
464 unsigned Line, unsigned Column,
465 bool PrologueEnd, bool IsStmt,
Reid Klecknereadc14f2016-09-07 16:15:31 +0000466 StringRef FileName, SMLoc Loc) {
Reid Kleckneraea52742018-08-28 23:25:59 +0000467 // Validate the directive.
468 if (!checkCVLocSection(FunctionId, FileNo, Loc))
469 return;
470
471 // Emit a label at the current position and record it in the CodeViewContext.
472 MCSymbol *LineSym = getContext().createTempSymbol();
473 EmitLabel(LineSym);
474 getContext().getCVContext().recordCVLoc(getContext(), LineSym, FunctionId,
475 FileNo, Line, Column, PrologueEnd,
476 IsStmt);
Reid Kleckner1689efb2016-01-29 00:49:42 +0000477}
478
479void MCObjectStreamer::EmitCVLinetableDirective(unsigned FunctionId,
480 const MCSymbol *Begin,
481 const MCSymbol *End) {
482 getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
483 End);
484 this->MCStreamer::EmitCVLinetableDirective(FunctionId, Begin, End);
485}
486
David Majnemer5c900cb2016-01-29 19:24:12 +0000487void MCObjectStreamer::EmitCVInlineLinetableDirective(
488 unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
Reid Klecknereadc14f2016-09-07 16:15:31 +0000489 const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
David Majnemer5c900cb2016-01-29 19:24:12 +0000490 getContext().getCVContext().emitInlineLineTableForFunction(
Reid Kleckner617bba82016-02-02 17:41:18 +0000491 *this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
Reid Klecknereadc14f2016-09-07 16:15:31 +0000492 FnEndSym);
David Majnemer5c900cb2016-01-29 19:24:12 +0000493 this->MCStreamer::EmitCVInlineLinetableDirective(
Reid Klecknereadc14f2016-09-07 16:15:31 +0000494 PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
David Majnemer5c900cb2016-01-29 19:24:12 +0000495}
496
David Majnemer7ddc5472016-02-05 01:55:49 +0000497void MCObjectStreamer::EmitCVDefRangeDirective(
498 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
499 StringRef FixedSizePortion) {
Reid Kleckner96b08732018-12-17 21:49:35 +0000500 MCFragment *Frag =
501 getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
502 // Attach labels that were pending before we created the defrange fragment to
503 // the beginning of the new fragment.
504 flushPendingLabels(Frag, 0);
David Majnemer7ddc5472016-02-05 01:55:49 +0000505 this->MCStreamer::EmitCVDefRangeDirective(Ranges, FixedSizePortion);
506}
507
Reid Kleckner1689efb2016-01-29 00:49:42 +0000508void MCObjectStreamer::EmitCVStringTableDirective() {
509 getContext().getCVContext().emitStringTable(*this);
510}
511void MCObjectStreamer::EmitCVFileChecksumsDirective() {
512 getContext().getCVContext().emitFileChecksums(*this);
513}
514
Reid Kleckner3796a452017-09-19 18:14:45 +0000515void MCObjectStreamer::EmitCVFileChecksumOffsetDirective(unsigned FileNo) {
516 getContext().getCVContext().emitFileChecksumOffset(*this, FileNo);
517}
Reid Kleckner1689efb2016-01-29 00:49:42 +0000518
Rafael Espindolaa3863ea2013-07-02 15:49:13 +0000519void MCObjectStreamer::EmitBytes(StringRef Data) {
Eric Christopherea40df32016-10-14 05:47:37 +0000520 MCDwarfLineEntry::Make(this, getCurrentSectionOnly());
Petr Hosekbc245c02015-06-27 01:54:17 +0000521 MCDataFragment *DF = getOrCreateDataFragment();
522 flushPendingLabels(DF, DF->getContents().size());
523 DF->getContents().append(Data.begin(), Data.end());
Eric Christopher42eb0822018-09-06 22:09:31 +0000524
525 // EmitBytes might not cover all possible ways we emit data (or could be used
526 // to emit executable code in some cases), but is the best method we have
527 // right now for checking this.
528 MCSection *Sec = getCurrentSectionOnly();
529 Sec->setHasData(true);
Benjamin Kramere660fc12012-10-04 13:12:43 +0000530}
531
532void MCObjectStreamer::EmitValueToAlignment(unsigned ByteAlignment,
533 int64_t Value,
534 unsigned ValueSize,
535 unsigned MaxBytesToEmit) {
536 if (MaxBytesToEmit == 0)
537 MaxBytesToEmit = ByteAlignment;
Peter Collingbournedf39be62013-04-17 21:18:16 +0000538 insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
Benjamin Kramere660fc12012-10-04 13:12:43 +0000539
540 // Update the maximum alignment on the current section if necessary.
Eric Christopherea40df32016-10-14 05:47:37 +0000541 MCSection *CurSec = getCurrentSectionOnly();
Rafael Espindola477acf62015-05-21 21:02:35 +0000542 if (ByteAlignment > CurSec->getAlignment())
543 CurSec->setAlignment(ByteAlignment);
Benjamin Kramere660fc12012-10-04 13:12:43 +0000544}
545
546void MCObjectStreamer::EmitCodeAlignment(unsigned ByteAlignment,
547 unsigned MaxBytesToEmit) {
548 EmitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
549 cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true);
550}
551
Rafael Espindola5ff5bdb2015-11-04 23:59:18 +0000552void MCObjectStreamer::emitValueToOffset(const MCExpr *Offset,
Oliver Stannardf4f85602016-12-14 10:43:58 +0000553 unsigned char Value,
554 SMLoc Loc) {
555 insert(new MCOrgFragment(*Offset, Value, Loc));
Rafael Espindolae2393052010-12-02 05:59:38 +0000556}
557
Omer Paparo Bivas1be670d2017-10-24 06:16:03 +0000558void MCObjectStreamer::EmitCodePaddingBasicBlockStart(
559 const MCCodePaddingContext &Context) {
560 getAssembler().getBackend().handleCodePaddingBasicBlockStart(this, Context);
561}
562
563void MCObjectStreamer::EmitCodePaddingBasicBlockEnd(
564 const MCCodePaddingContext &Context) {
565 getAssembler().getBackend().handleCodePaddingBasicBlockEnd(Context);
566}
567
Simon Atanasyanb469a382016-08-22 16:18:42 +0000568// Associate DTPRel32 fixup with data and resize data area
569void MCObjectStreamer::EmitDTPRel32Value(const MCExpr *Value) {
570 MCDataFragment *DF = getOrCreateDataFragment();
571 flushPendingLabels(DF, DF->getContents().size());
572
573 DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
574 Value, FK_DTPRel_4));
575 DF->getContents().resize(DF->getContents().size() + 4, 0);
576}
577
578// Associate DTPRel64 fixup with data and resize data area
579void MCObjectStreamer::EmitDTPRel64Value(const MCExpr *Value) {
580 MCDataFragment *DF = getOrCreateDataFragment();
581 flushPendingLabels(DF, DF->getContents().size());
582
583 DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
584 Value, FK_DTPRel_8));
585 DF->getContents().resize(DF->getContents().size() + 8, 0);
586}
587
588// Associate TPRel32 fixup with data and resize data area
589void MCObjectStreamer::EmitTPRel32Value(const MCExpr *Value) {
590 MCDataFragment *DF = getOrCreateDataFragment();
591 flushPendingLabels(DF, DF->getContents().size());
592
593 DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
594 Value, FK_TPRel_4));
595 DF->getContents().resize(DF->getContents().size() + 4, 0);
596}
597
598// Associate TPRel64 fixup with data and resize data area
599void MCObjectStreamer::EmitTPRel64Value(const MCExpr *Value) {
600 MCDataFragment *DF = getOrCreateDataFragment();
601 flushPendingLabels(DF, DF->getContents().size());
602
603 DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
604 Value, FK_TPRel_8));
605 DF->getContents().resize(DF->getContents().size() + 8, 0);
606}
607
Akira Hatanaka84bfc2f2011-11-23 22:18:04 +0000608// Associate GPRel32 fixup with data and resize data area
609void MCObjectStreamer::EmitGPRel32Value(const MCExpr *Value) {
610 MCDataFragment *DF = getOrCreateDataFragment();
Petr Hosekbc245c02015-06-27 01:54:17 +0000611 flushPendingLabels(DF, DF->getContents().size());
Akira Hatanaka84bfc2f2011-11-23 22:18:04 +0000612
Weiming Zhaoc4d38012017-04-03 21:50:04 +0000613 DF->getFixups().push_back(
614 MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
Akira Hatanaka84bfc2f2011-11-23 22:18:04 +0000615 DF->getContents().resize(DF->getContents().size() + 4, 0);
616}
617
Simon Atanasyanb469a382016-08-22 16:18:42 +0000618// Associate GPRel64 fixup with data and resize data area
Jack Carter101771b2012-08-22 00:49:30 +0000619void MCObjectStreamer::EmitGPRel64Value(const MCExpr *Value) {
620 MCDataFragment *DF = getOrCreateDataFragment();
Petr Hosekbc245c02015-06-27 01:54:17 +0000621 flushPendingLabels(DF, DF->getContents().size());
Jack Carter101771b2012-08-22 00:49:30 +0000622
Weiming Zhaoc4d38012017-04-03 21:50:04 +0000623 DF->getFixups().push_back(
624 MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
Jack Carter101771b2012-08-22 00:49:30 +0000625 DF->getContents().resize(DF->getContents().size() + 8, 0);
626}
627
Daniel Sanders7056b682015-11-12 13:33:00 +0000628bool MCObjectStreamer::EmitRelocDirective(const MCExpr &Offset, StringRef Name,
Peter Smithe2b2a912018-06-06 09:40:06 +0000629 const MCExpr *Expr, SMLoc Loc,
630 const MCSubtargetInfo &STI) {
David Majnemer42a735c2016-01-19 23:05:27 +0000631 Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
632 if (!MaybeKind.hasValue())
Daniel Sanders7056b682015-11-12 13:33:00 +0000633 return true;
634
David Majnemer42a735c2016-01-19 23:05:27 +0000635 MCFixupKind Kind = *MaybeKind;
636
Daniel Sanders7056b682015-11-12 13:33:00 +0000637 if (Expr == nullptr)
638 Expr =
639 MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
Vladimir Stefanovica7270f92018-11-21 16:28:39 +0000640
641 MCDataFragment *DF = getOrCreateDataFragment(&STI);
642 flushPendingLabels(DF, DF->getContents().size());
643
644 int64_t OffsetValue;
645 if (Offset.evaluateAsAbsolute(OffsetValue)) {
646 if (OffsetValue < 0)
647 llvm_unreachable(".reloc offset is negative");
648 DF->getFixups().push_back(MCFixup::create(OffsetValue, Expr, Kind, Loc));
649 return false;
650 }
651
652 if (Offset.getKind() != llvm::MCExpr::SymbolRef)
653 llvm_unreachable(".reloc offset is not absolute nor a label");
654
655 const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(Offset);
656 if (SRE.getSymbol().isDefined()) {
657 DF->getFixups().push_back(MCFixup::create(SRE.getSymbol().getOffset(),
658 Expr, Kind, Loc));
659 return false;
660 }
661
662 PendingFixups.emplace_back(&SRE.getSymbol(), DF,
663 MCFixup::create(-1, Expr, Kind, Loc));
Daniel Sanders7056b682015-11-12 13:33:00 +0000664 return false;
665}
666
Petr Hosek27f2fb02016-05-28 05:57:48 +0000667void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
668 SMLoc Loc) {
669 MCDataFragment *DF = getOrCreateDataFragment();
670 flushPendingLabels(DF, DF->getContents().size());
671
Rafael Espindola6ec8f0b2018-01-09 19:29:33 +0000672 assert(getCurrentSectionOnly() && "need a section");
Nirav Davecdcd5e12018-05-18 17:45:48 +0000673 insert(new MCFillFragment(FillValue, 1, NumBytes, Loc));
Petr Hosek27f2fb02016-05-28 05:57:48 +0000674}
675
676void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
677 int64_t Expr, SMLoc Loc) {
678 int64_t IntNumValues;
Nirav Davecdcd5e12018-05-18 17:45:48 +0000679 // Do additional checking now if we can resolve the value.
680 if (NumValues.evaluateAsAbsolute(IntNumValues, getAssemblerPtr())) {
681 if (IntNumValues < 0) {
682 getContext().getSourceManager()->PrintMessage(
683 Loc, SourceMgr::DK_Warning,
684 "'.fill' directive with negative repeat count has no effect");
685 return;
686 }
687 // Emit now if we can for better errors.
688 int64_t NonZeroSize = Size > 4 ? 4 : Size;
689 Expr &= ~0ULL >> (64 - NonZeroSize * 8);
690 for (uint64_t i = 0, e = IntNumValues; i != e; ++i) {
691 EmitIntValue(Expr, NonZeroSize);
692 if (NonZeroSize < Size)
693 EmitIntValue(0, Size - NonZeroSize);
694 }
Petr Hosek27f2fb02016-05-28 05:57:48 +0000695 return;
696 }
697
Nirav Davecdcd5e12018-05-18 17:45:48 +0000698 // Otherwise emit as fragment.
699 MCDataFragment *DF = getOrCreateDataFragment();
700 flushPendingLabels(DF, DF->getContents().size());
Petr Hosek27f2fb02016-05-28 05:57:48 +0000701
Nirav Davecdcd5e12018-05-18 17:45:48 +0000702 assert(getCurrentSectionOnly() && "need a section");
703 insert(new MCFillFragment(Expr, Size, NumValues, Loc));
Petr Hosek27f2fb02016-05-28 05:57:48 +0000704}
705
Peter Collingbourne6387bda2017-03-03 21:22:06 +0000706void MCObjectStreamer::EmitFileDirective(StringRef Filename) {
707 getAssembler().addFileName(Filename);
708}
709
Peter Collingbournea29ff2e2018-07-17 22:17:18 +0000710void MCObjectStreamer::EmitAddrsig() {
711 getAssembler().getWriter().emitAddrsigSection();
712}
713
714void MCObjectStreamer::EmitAddrsigSym(const MCSymbol *Sym) {
715 getAssembler().registerSymbol(*Sym);
716 getAssembler().getWriter().addAddrsigSymbol(Sym);
717}
718
Rafael Espindola99b42372012-01-07 03:13:18 +0000719void MCObjectStreamer::FinishImpl() {
Jonas Devliegheref0c06bd2018-07-11 12:30:35 +0000720 getContext().RemapDebugPaths();
Paul Robinson4575d342018-07-10 14:41:54 +0000721
Kevin Enderby94c2e852011-12-09 18:09:40 +0000722 // If we are generating dwarf for assembly source files dump out the sections.
723 if (getContext().getGenDwarfForAssembly())
David Blaikie5b2de5d2014-04-01 07:35:52 +0000724 MCGenDwarfInfo::Emit(this);
725
726 // Dump out the dwarf file & directory tables and line tables.
Frederic Riss796478f2015-08-07 15:14:08 +0000727 MCDwarfLineTable::Emit(this, getAssembler().getDWARFLinetableParams());
Kevin Enderby94c2e852011-12-09 18:09:40 +0000728
Jonas Devlieghere74dc4042018-07-10 15:32:17 +0000729 flushPendingLabels();
Vladimir Stefanovica7270f92018-11-21 16:28:39 +0000730 resolvePendingFixups();
Daniel Dunbar83b46712010-06-16 20:04:25 +0000731 getAssembler().Finish();
732}