blob: b026277ac6243f481bebd89f821c55977c0441eb [file] [log] [blame]
Chris Lattnereb72dca2010-07-11 22:05:00 +00001//===-- llvm/MC/WinCOFFStreamer.cpp -----------------------------*- C++ -*-===//
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// This file contains an implementation of a Win32 COFF object file streamer.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "WinCOFFStreamer"
15
16#include "llvm/MC/MCObjectStreamer.h"
17#include "llvm/MC/MCContext.h"
18#include "llvm/MC/MCSection.h"
19#include "llvm/MC/MCSymbol.h"
20#include "llvm/MC/MCExpr.h"
Michael J. Spencer8067adc2010-07-19 06:13:10 +000021#include "llvm/MC/MCValue.h"
22#include "llvm/MC/MCAssembler.h"
23#include "llvm/MC/MCAsmLayout.h"
Chris Lattnereb72dca2010-07-11 22:05:00 +000024#include "llvm/MC/MCCodeEmitter.h"
25#include "llvm/MC/MCSectionCOFF.h"
Charles Davis3185f5c2011-05-22 03:01:05 +000026#include "llvm/MC/MCWin64EH.h"
Evan Cheng78c10ee2011-07-25 23:24:55 +000027#include "llvm/MC/MCAsmBackend.h"
Michael J. Spencer8067adc2010-07-19 06:13:10 +000028
Chris Lattnereb72dca2010-07-11 22:05:00 +000029#include "llvm/Support/COFF.h"
30#include "llvm/Support/Debug.h"
31#include "llvm/Support/ErrorHandling.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000032#include "llvm/Support/TargetRegistry.h"
Chris Lattnereb72dca2010-07-11 22:05:00 +000033#include "llvm/Support/raw_ostream.h"
Rafael Espindola8f7d12c2011-12-17 01:14:52 +000034
Chris Lattnereb72dca2010-07-11 22:05:00 +000035using namespace llvm;
36
Chris Lattnereb72dca2010-07-11 22:05:00 +000037namespace {
38class WinCOFFStreamer : public MCObjectStreamer {
39public:
Michael J. Spencer8067adc2010-07-19 06:13:10 +000040 MCSymbol const *CurSymbol;
41
Chris Lattnereb72dca2010-07-11 22:05:00 +000042 WinCOFFStreamer(MCContext &Context,
Evan Cheng78c10ee2011-07-25 23:24:55 +000043 MCAsmBackend &MAB,
Chris Lattnereb72dca2010-07-11 22:05:00 +000044 MCCodeEmitter &CE,
45 raw_ostream &OS);
46
Michael J. Spencer8067adc2010-07-19 06:13:10 +000047 void AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
48 unsigned ByteAlignment, bool External);
49
Chris Lattnereb72dca2010-07-11 22:05:00 +000050 // MCStreamer interface
51
Rafael Espindolad80781b2010-09-15 21:48:40 +000052 virtual void InitSections();
Rafael Espindolaba210242010-11-28 16:22:59 +000053 virtual void EmitLabel(MCSymbol *Symbol);
Chris Lattnereb72dca2010-07-11 22:05:00 +000054 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
Jim Grosbachce792992010-11-05 22:08:08 +000055 virtual void EmitThumbFunc(MCSymbol *Func);
Chris Lattnereb72dca2010-07-11 22:05:00 +000056 virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
57 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
58 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
59 virtual void BeginCOFFSymbolDef(MCSymbol const *Symbol);
60 virtual void EmitCOFFSymbolStorageClass(int StorageClass);
61 virtual void EmitCOFFSymbolType(int Type);
62 virtual void EndCOFFSymbolDef();
Rafael Espindola8f7d12c2011-12-17 01:14:52 +000063 virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
Chris Lattnereb72dca2010-07-11 22:05:00 +000064 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
65 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000066 unsigned ByteAlignment);
Benjamin Kramer36a16012011-09-01 23:04:27 +000067 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
68 unsigned ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +000069 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Evan Chengc90a1fc2012-06-22 20:14:46 +000070 uint64_t Size,unsigned ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +000071 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000072 uint64_t Size, unsigned ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +000073 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
Chris Lattnereb72dca2010-07-11 22:05:00 +000074 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
Michael J. Spencer8067adc2010-07-19 06:13:10 +000075 unsigned ValueSize, unsigned MaxBytesToEmit);
Chris Lattnereb72dca2010-07-11 22:05:00 +000076 virtual void EmitCodeAlignment(unsigned ByteAlignment,
77 unsigned MaxBytesToEmit);
Chris Lattnereb72dca2010-07-11 22:05:00 +000078 virtual void EmitFileDirective(StringRef Filename);
Chris Lattnereb72dca2010-07-11 22:05:00 +000079 virtual void EmitInstruction(const MCInst &Instruction);
Charles Davis3185f5c2011-05-22 03:01:05 +000080 virtual void EmitWin64EHHandlerData();
Rafael Espindola99b42372012-01-07 03:13:18 +000081 virtual void FinishImpl();
Michael J. Spencer192d1362010-10-09 15:44:27 +000082
83private:
Rafael Espindolaf89671d2010-11-01 16:27:31 +000084 virtual void EmitInstToFragment(const MCInst &Inst) {
85 llvm_unreachable("Not used by WinCOFF.");
86 }
87 virtual void EmitInstToData(const MCInst &Inst) {
88 llvm_unreachable("Not used by WinCOFF.");
89 }
90
Michael J. Spencer192d1362010-10-09 15:44:27 +000091 void SetSection(StringRef Section,
92 unsigned Characteristics,
93 SectionKind Kind) {
94 SwitchSection(getContext().getCOFFSection(Section, Characteristics, Kind));
95 }
96
97 void SetSectionText() {
98 SetSection(".text",
99 COFF::IMAGE_SCN_CNT_CODE
100 | COFF::IMAGE_SCN_MEM_EXECUTE
101 | COFF::IMAGE_SCN_MEM_READ,
102 SectionKind::getText());
103 EmitCodeAlignment(4, 0);
104 }
105
106 void SetSectionData() {
107 SetSection(".data",
108 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA
109 | COFF::IMAGE_SCN_MEM_READ
110 | COFF::IMAGE_SCN_MEM_WRITE,
111 SectionKind::getDataRel());
112 EmitCodeAlignment(4, 0);
113 }
114
115 void SetSectionBSS() {
116 SetSection(".bss",
117 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA
118 | COFF::IMAGE_SCN_MEM_READ
119 | COFF::IMAGE_SCN_MEM_WRITE,
120 SectionKind::getBSS());
121 EmitCodeAlignment(4, 0);
122 }
123
Chris Lattnereb72dca2010-07-11 22:05:00 +0000124};
125} // end anonymous namespace.
126
127WinCOFFStreamer::WinCOFFStreamer(MCContext &Context,
Evan Cheng78c10ee2011-07-25 23:24:55 +0000128 MCAsmBackend &MAB,
Chris Lattnereb72dca2010-07-11 22:05:00 +0000129 MCCodeEmitter &CE,
130 raw_ostream &OS)
Evan Cheng78c10ee2011-07-25 23:24:55 +0000131 : MCObjectStreamer(Context, MAB, OS, &CE)
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000132 , CurSymbol(NULL) {
133}
134
135void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
136 unsigned ByteAlignment, bool External) {
137 assert(!Symbol->isInSection() && "Symbol must not already have a section!");
138
139 std::string SectionName(".bss$linkonce");
140 SectionName.append(Symbol->getName().begin(), Symbol->getName().end());
141
142 MCSymbolData &SymbolData = getAssembler().getOrCreateSymbolData(*Symbol);
143
144 unsigned Characteristics =
145 COFF::IMAGE_SCN_LNK_COMDAT |
146 COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
147 COFF::IMAGE_SCN_MEM_READ |
148 COFF::IMAGE_SCN_MEM_WRITE;
149
150 int Selection = COFF::IMAGE_COMDAT_SELECT_LARGEST;
151
152 const MCSection *Section = MCStreamer::getContext().getCOFFSection(
153 SectionName, Characteristics, Selection, SectionKind::getBSS());
154
155 MCSectionData &SectionData = getAssembler().getOrCreateSectionData(*Section);
156
157 if (SectionData.getAlignment() < ByteAlignment)
158 SectionData.setAlignment(ByteAlignment);
159
160 SymbolData.setExternal(External);
161
162 Symbol->setSection(*Section);
163
164 if (ByteAlignment != 1)
165 new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, &SectionData);
166
167 SymbolData.setFragment(new MCFillFragment(0, 0, Size, &SectionData));
Chris Lattnereb72dca2010-07-11 22:05:00 +0000168}
169
170// MCStreamer interface
171
Rafael Espindolad80781b2010-09-15 21:48:40 +0000172void WinCOFFStreamer::InitSections() {
Michael J. Spencer192d1362010-10-09 15:44:27 +0000173 SetSectionText();
174 SetSectionData();
175 SetSectionBSS();
176 SetSectionText();
Rafael Espindolad80781b2010-09-15 21:48:40 +0000177}
178
Rafael Espindolaba210242010-11-28 16:22:59 +0000179void WinCOFFStreamer::EmitLabel(MCSymbol *Symbol) {
Rafael Espindolaba210242010-11-28 16:22:59 +0000180 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
Rafael Espindolaea4afa92010-11-28 17:18:55 +0000181 MCObjectStreamer::EmitLabel(Symbol);
Rafael Espindolaba210242010-11-28 16:22:59 +0000182}
183
Chris Lattnereb72dca2010-07-11 22:05:00 +0000184void WinCOFFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000185 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000186}
187
Jim Grosbachce792992010-11-05 22:08:08 +0000188void WinCOFFStreamer::EmitThumbFunc(MCSymbol *Func) {
189 llvm_unreachable("not implemented");
190}
191
Chris Lattnereb72dca2010-07-11 22:05:00 +0000192void WinCOFFStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000193 assert((Symbol->isInSection()
194 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
195 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencerb5814a32010-10-07 06:29:33 +0000196 // FIXME: This is all very ugly and depressing. What needs to happen here
197 // depends on quite a few things that are all part of relaxation, which we
198 // don't really even do.
199
200 if (Value->getKind() != MCExpr::SymbolRef) {
NAKAMURA Takumi86c36472010-10-07 07:21:04 +0000201 // TODO: This is exactly the same as MachOStreamer. Consider merging into
202 // MCObjectStreamer.
203 getAssembler().getOrCreateSymbolData(*Symbol);
204 AddValueSymbols(Value);
Michael J. Spencerb5814a32010-10-07 06:29:33 +0000205 Symbol->setVariableValue(Value);
206 } else {
207 // FIXME: This is a horrible way to do this :(. This should really be
208 // handled after we are done with the MC* objects and immediately before
209 // writing out the object file when we know exactly what the symbol should
210 // look like in the coff symbol table. I'm not doing that now because the
211 // COFF object writer doesn't have a clearly defined separation between MC
212 // data structures, the object writers data structures, and the raw, POD,
213 // data structures that get written to disk.
214
215 // Copy over the aliased data.
216 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
217 const MCSymbolData &RealSD = getAssembler().getOrCreateSymbolData(
218 dyn_cast<const MCSymbolRefExpr>(Value)->getSymbol());
219
220 // FIXME: This is particularly nasty because it breaks as soon as any data
221 // members of MCSymbolData change.
222 SD.CommonAlign = RealSD.CommonAlign;
223 SD.CommonSize = RealSD.CommonSize;
224 SD.Flags = RealSD.Flags;
225 SD.Fragment = RealSD.Fragment;
226 SD.Index = RealSD.Index;
227 SD.IsExternal = RealSD.IsExternal;
228 SD.IsPrivateExtern = RealSD.IsPrivateExtern;
229 SD.Offset = RealSD.Offset;
230 SD.SymbolSize = RealSD.SymbolSize;
231 }
Chris Lattnereb72dca2010-07-11 22:05:00 +0000232}
233
234void WinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
235 MCSymbolAttr Attribute) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000236 assert(Symbol && "Symbol must be non-null!");
237 assert((Symbol->isInSection()
238 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
239 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000240 switch (Attribute) {
241 case MCSA_WeakReference:
Michael J. Spencer4cee2892010-10-16 08:25:57 +0000242 case MCSA_Weak: {
243 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
244 SD.modifyFlags(COFF::SF_WeakExternal, COFF::SF_WeakExternal);
245 SD.setExternal(true);
246 }
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000247 break;
248
249 case MCSA_Global:
250 getAssembler().getOrCreateSymbolData(*Symbol).setExternal(true);
251 break;
252
253 default:
254 llvm_unreachable("unsupported attribute");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000255 }
Chris Lattnereb72dca2010-07-11 22:05:00 +0000256}
257
258void WinCOFFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000259 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000260}
261
262void WinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *Symbol) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000263 assert((Symbol->isInSection()
264 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
265 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000266 assert(CurSymbol == NULL && "EndCOFFSymbolDef must be called between calls "
267 "to BeginCOFFSymbolDef!");
268 CurSymbol = Symbol;
Chris Lattnereb72dca2010-07-11 22:05:00 +0000269}
270
271void WinCOFFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000272 assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
273 assert((StorageClass & ~0xFF) == 0 && "StorageClass must only have data in "
274 "the first byte!");
275
276 getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags(
277 StorageClass << COFF::SF_ClassShift,
278 COFF::SF_ClassMask);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000279}
280
281void WinCOFFStreamer::EmitCOFFSymbolType(int Type) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000282 assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
283 assert((Type & ~0xFFFF) == 0 && "Type must only have data in the first 2 "
284 "bytes");
285
286 getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags(
287 Type << COFF::SF_TypeShift,
288 COFF::SF_TypeMask);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000289}
290
291void WinCOFFStreamer::EndCOFFSymbolDef() {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000292 assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
293 CurSymbol = NULL;
Chris Lattnereb72dca2010-07-11 22:05:00 +0000294}
295
Rafael Espindola8f7d12c2011-12-17 01:14:52 +0000296void WinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol)
297{
298 MCDataFragment *DF = getOrCreateDataFragment();
299
300 DF->addFixup(MCFixup::Create(DF->getContents().size(),
301 MCSymbolRefExpr::Create (Symbol, getContext ()),
Rafael Espindolace618af2011-12-24 14:47:52 +0000302 FK_SecRel_4));
Rafael Espindola8f7d12c2011-12-17 01:14:52 +0000303 DF->getContents().resize(DF->getContents().size() + 4, 0);
304}
305
Chris Lattnereb72dca2010-07-11 22:05:00 +0000306void WinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000307 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000308}
309
310void WinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000311 unsigned ByteAlignment) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000312 assert((Symbol->isInSection()
313 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
314 : true) && "Got non COFF section in the COFF backend!");
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000315 AddCommonSymbol(Symbol, Size, ByteAlignment, true);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000316}
317
Benjamin Kramer36a16012011-09-01 23:04:27 +0000318void WinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
319 unsigned ByteAlignment) {
Michael J. Spencerd47f4a92010-10-09 11:00:37 +0000320 assert((Symbol->isInSection()
321 ? Symbol->getSection().getVariant() == MCSection::SV_COFF
322 : true) && "Got non COFF section in the COFF backend!");
Benjamin Kramer36a16012011-09-01 23:04:27 +0000323 AddCommonSymbol(Symbol, Size, ByteAlignment, false);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000324}
325
326void WinCOFFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
Evan Chengc90a1fc2012-06-22 20:14:46 +0000327 uint64_t Size,unsigned ByteAlignment) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000328 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000329}
330
331void WinCOFFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
332 uint64_t Size, unsigned ByteAlignment) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000333 llvm_unreachable("not implemented");
Chris Lattnereb72dca2010-07-11 22:05:00 +0000334}
335
336void WinCOFFStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000337 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
338 // MCObjectStreamer?
339 getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end());
Chris Lattnereb72dca2010-07-11 22:05:00 +0000340}
341
Chris Lattnereb72dca2010-07-11 22:05:00 +0000342void WinCOFFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000343 int64_t Value,
344 unsigned ValueSize,
345 unsigned MaxBytesToEmit) {
346 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
347 // MCObjectStreamer?
348 if (MaxBytesToEmit == 0)
349 MaxBytesToEmit = ByteAlignment;
350 new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit,
351 getCurrentSectionData());
352
353 // Update the maximum alignment on the current section if necessary.
354 if (ByteAlignment > getCurrentSectionData()->getAlignment())
355 getCurrentSectionData()->setAlignment(ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000356}
357
358void WinCOFFStreamer::EmitCodeAlignment(unsigned ByteAlignment,
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000359 unsigned MaxBytesToEmit) {
360 // TODO: This is copied exactly from the MachOStreamer. Consider merging into
361 // MCObjectStreamer?
362 if (MaxBytesToEmit == 0)
363 MaxBytesToEmit = ByteAlignment;
364 MCAlignFragment *F = new MCAlignFragment(ByteAlignment, 0, 1, MaxBytesToEmit,
365 getCurrentSectionData());
366 F->setEmitNops(true);
367
368 // Update the maximum alignment on the current section if necessary.
369 if (ByteAlignment > getCurrentSectionData()->getAlignment())
370 getCurrentSectionData()->setAlignment(ByteAlignment);
Chris Lattnereb72dca2010-07-11 22:05:00 +0000371}
372
Chris Lattnereb72dca2010-07-11 22:05:00 +0000373void WinCOFFStreamer::EmitFileDirective(StringRef Filename) {
374 // Ignore for now, linkers don't care, and proper debug
375 // info will be a much large effort.
376}
377
Chris Lattnereb72dca2010-07-11 22:05:00 +0000378void WinCOFFStreamer::EmitInstruction(const MCInst &Instruction) {
Michael J. Spencer8067adc2010-07-19 06:13:10 +0000379 for (unsigned i = 0, e = Instruction.getNumOperands(); i != e; ++i)
380 if (Instruction.getOperand(i).isExpr())
381 AddValueSymbols(Instruction.getOperand(i).getExpr());
382
383 getCurrentSectionData()->setHasInstructions(true);
384
385 MCInstFragment *Fragment =
386 new MCInstFragment(Instruction, getCurrentSectionData());
387
388 raw_svector_ostream VecOS(Fragment->getCode());
389
390 getAssembler().getEmitter().EncodeInstruction(Instruction, VecOS,
391 Fragment->getFixups());
Chris Lattnereb72dca2010-07-11 22:05:00 +0000392}
393
Charles Davis3185f5c2011-05-22 03:01:05 +0000394void WinCOFFStreamer::EmitWin64EHHandlerData() {
395 MCStreamer::EmitWin64EHHandlerData();
396
397 // We have to emit the unwind info now, because this directive
398 // actually switches to the .xdata section!
399 MCWin64EHUnwindEmitter::EmitUnwindInfo(*this, getCurrentW64UnwindInfo());
400}
401
Rafael Espindola99b42372012-01-07 03:13:18 +0000402void WinCOFFStreamer::FinishImpl() {
Charles Davis38ea9ee2011-05-22 04:15:07 +0000403 EmitW64Tables();
Rafael Espindola99b42372012-01-07 03:13:18 +0000404 MCObjectStreamer::FinishImpl();
Chris Lattnereb72dca2010-07-11 22:05:00 +0000405}
406
407namespace llvm
408{
409 MCStreamer *createWinCOFFStreamer(MCContext &Context,
Evan Cheng78c10ee2011-07-25 23:24:55 +0000410 MCAsmBackend &MAB,
Chris Lattnereb72dca2010-07-11 22:05:00 +0000411 MCCodeEmitter &CE,
Michael J. Spencere2195d82010-07-31 06:22:29 +0000412 raw_ostream &OS,
413 bool RelaxAll) {
Evan Cheng78c10ee2011-07-25 23:24:55 +0000414 WinCOFFStreamer *S = new WinCOFFStreamer(Context, MAB, CE, OS);
Michael J. Spencere2195d82010-07-31 06:22:29 +0000415 S->getAssembler().setRelaxAll(RelaxAll);
416 return S;
Chris Lattnereb72dca2010-07-11 22:05:00 +0000417 }
418}