Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 1 | //===-- 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 | |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCStreamer.h" |
Evan Cheng | 78c10ee | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCAsmBackend.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCAsmLayout.h" |
| 19 | #include "llvm/MC/MCAssembler.h" |
| 20 | #include "llvm/MC/MCCodeEmitter.h" |
| 21 | #include "llvm/MC/MCContext.h" |
| 22 | #include "llvm/MC/MCExpr.h" |
| 23 | #include "llvm/MC/MCObjectStreamer.h" |
| 24 | #include "llvm/MC/MCSection.h" |
| 25 | #include "llvm/MC/MCSectionCOFF.h" |
| 26 | #include "llvm/MC/MCSymbol.h" |
| 27 | #include "llvm/MC/MCValue.h" |
| 28 | #include "llvm/MC/MCWin64EH.h" |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 29 | #include "llvm/Support/COFF.h" |
| 30 | #include "llvm/Support/Debug.h" |
| 31 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | 3e74d6f | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 32 | #include "llvm/Support/TargetRegistry.h" |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 33 | #include "llvm/Support/raw_ostream.h" |
Rafael Espindola | 8f7d12c | 2011-12-17 01:14:52 +0000 | [diff] [blame] | 34 | |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 35 | using namespace llvm; |
| 36 | |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 37 | namespace { |
| 38 | class WinCOFFStreamer : public MCObjectStreamer { |
| 39 | public: |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 40 | MCSymbol const *CurSymbol; |
| 41 | |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 42 | WinCOFFStreamer(MCContext &Context, |
Evan Cheng | 78c10ee | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 43 | MCAsmBackend &MAB, |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 44 | MCCodeEmitter &CE, |
| 45 | raw_ostream &OS); |
| 46 | |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 47 | void AddCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
| 48 | unsigned ByteAlignment, bool External); |
| 49 | |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 50 | // MCStreamer interface |
| 51 | |
Rafael Espindola | d80781b | 2010-09-15 21:48:40 +0000 | [diff] [blame] | 52 | virtual void InitSections(); |
Rafael Espindola | ba21024 | 2010-11-28 16:22:59 +0000 | [diff] [blame] | 53 | virtual void EmitLabel(MCSymbol *Symbol); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 54 | virtual void EmitAssemblerFlag(MCAssemblerFlag Flag); |
Jim Grosbach | ce79299 | 2010-11-05 22:08:08 +0000 | [diff] [blame] | 55 | virtual void EmitThumbFunc(MCSymbol *Func); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 56 | 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 Espindola | 8f7d12c | 2011-12-17 01:14:52 +0000 | [diff] [blame] | 63 | virtual void EmitCOFFSecRel32(MCSymbol const *Symbol); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 64 | virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value); |
| 65 | virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 66 | unsigned ByteAlignment); |
Benjamin Kramer | 36a1601 | 2011-09-01 23:04:27 +0000 | [diff] [blame] | 67 | virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
| 68 | unsigned ByteAlignment); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 69 | virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol, |
Evan Cheng | c90a1fc | 2012-06-22 20:14:46 +0000 | [diff] [blame] | 70 | uint64_t Size,unsigned ByteAlignment); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 71 | virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 72 | uint64_t Size, unsigned ByteAlignment); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 73 | virtual void EmitFileDirective(StringRef Filename); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 74 | virtual void EmitInstruction(const MCInst &Instruction); |
Charles Davis | 3185f5c | 2011-05-22 03:01:05 +0000 | [diff] [blame] | 75 | virtual void EmitWin64EHHandlerData(); |
Rafael Espindola | 99b4237 | 2012-01-07 03:13:18 +0000 | [diff] [blame] | 76 | virtual void FinishImpl(); |
Michael J. Spencer | 192d136 | 2010-10-09 15:44:27 +0000 | [diff] [blame] | 77 | |
| 78 | private: |
Rafael Espindola | f89671d | 2010-11-01 16:27:31 +0000 | [diff] [blame] | 79 | virtual void EmitInstToFragment(const MCInst &Inst) { |
| 80 | llvm_unreachable("Not used by WinCOFF."); |
| 81 | } |
| 82 | virtual void EmitInstToData(const MCInst &Inst) { |
| 83 | llvm_unreachable("Not used by WinCOFF."); |
| 84 | } |
| 85 | |
Michael J. Spencer | 192d136 | 2010-10-09 15:44:27 +0000 | [diff] [blame] | 86 | void SetSection(StringRef Section, |
| 87 | unsigned Characteristics, |
| 88 | SectionKind Kind) { |
| 89 | SwitchSection(getContext().getCOFFSection(Section, Characteristics, Kind)); |
| 90 | } |
| 91 | |
| 92 | void SetSectionText() { |
| 93 | SetSection(".text", |
| 94 | COFF::IMAGE_SCN_CNT_CODE |
| 95 | | COFF::IMAGE_SCN_MEM_EXECUTE |
| 96 | | COFF::IMAGE_SCN_MEM_READ, |
| 97 | SectionKind::getText()); |
| 98 | EmitCodeAlignment(4, 0); |
| 99 | } |
| 100 | |
| 101 | void SetSectionData() { |
| 102 | SetSection(".data", |
| 103 | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
| 104 | | COFF::IMAGE_SCN_MEM_READ |
| 105 | | COFF::IMAGE_SCN_MEM_WRITE, |
| 106 | SectionKind::getDataRel()); |
| 107 | EmitCodeAlignment(4, 0); |
| 108 | } |
| 109 | |
| 110 | void SetSectionBSS() { |
| 111 | SetSection(".bss", |
| 112 | COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
| 113 | | COFF::IMAGE_SCN_MEM_READ |
| 114 | | COFF::IMAGE_SCN_MEM_WRITE, |
| 115 | SectionKind::getBSS()); |
| 116 | EmitCodeAlignment(4, 0); |
| 117 | } |
| 118 | |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 119 | }; |
| 120 | } // end anonymous namespace. |
| 121 | |
| 122 | WinCOFFStreamer::WinCOFFStreamer(MCContext &Context, |
Evan Cheng | 78c10ee | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 123 | MCAsmBackend &MAB, |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 124 | MCCodeEmitter &CE, |
| 125 | raw_ostream &OS) |
Evan Cheng | 78c10ee | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 126 | : MCObjectStreamer(Context, MAB, OS, &CE) |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 127 | , CurSymbol(NULL) { |
| 128 | } |
| 129 | |
| 130 | void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
| 131 | unsigned ByteAlignment, bool External) { |
| 132 | assert(!Symbol->isInSection() && "Symbol must not already have a section!"); |
| 133 | |
| 134 | std::string SectionName(".bss$linkonce"); |
| 135 | SectionName.append(Symbol->getName().begin(), Symbol->getName().end()); |
| 136 | |
| 137 | MCSymbolData &SymbolData = getAssembler().getOrCreateSymbolData(*Symbol); |
| 138 | |
| 139 | unsigned Characteristics = |
| 140 | COFF::IMAGE_SCN_LNK_COMDAT | |
| 141 | COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | |
| 142 | COFF::IMAGE_SCN_MEM_READ | |
| 143 | COFF::IMAGE_SCN_MEM_WRITE; |
| 144 | |
| 145 | int Selection = COFF::IMAGE_COMDAT_SELECT_LARGEST; |
| 146 | |
| 147 | const MCSection *Section = MCStreamer::getContext().getCOFFSection( |
| 148 | SectionName, Characteristics, Selection, SectionKind::getBSS()); |
| 149 | |
| 150 | MCSectionData &SectionData = getAssembler().getOrCreateSectionData(*Section); |
| 151 | |
| 152 | if (SectionData.getAlignment() < ByteAlignment) |
| 153 | SectionData.setAlignment(ByteAlignment); |
| 154 | |
| 155 | SymbolData.setExternal(External); |
| 156 | |
| 157 | Symbol->setSection(*Section); |
| 158 | |
| 159 | if (ByteAlignment != 1) |
| 160 | new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, &SectionData); |
| 161 | |
| 162 | SymbolData.setFragment(new MCFillFragment(0, 0, Size, &SectionData)); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | // MCStreamer interface |
| 166 | |
Rafael Espindola | d80781b | 2010-09-15 21:48:40 +0000 | [diff] [blame] | 167 | void WinCOFFStreamer::InitSections() { |
Michael J. Spencer | 192d136 | 2010-10-09 15:44:27 +0000 | [diff] [blame] | 168 | SetSectionText(); |
| 169 | SetSectionData(); |
| 170 | SetSectionBSS(); |
| 171 | SetSectionText(); |
Rafael Espindola | d80781b | 2010-09-15 21:48:40 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Rafael Espindola | ba21024 | 2010-11-28 16:22:59 +0000 | [diff] [blame] | 174 | void WinCOFFStreamer::EmitLabel(MCSymbol *Symbol) { |
Rafael Espindola | ba21024 | 2010-11-28 16:22:59 +0000 | [diff] [blame] | 175 | assert(Symbol->isUndefined() && "Cannot define a symbol twice!"); |
Rafael Espindola | ea4afa9 | 2010-11-28 17:18:55 +0000 | [diff] [blame] | 176 | MCObjectStreamer::EmitLabel(Symbol); |
Rafael Espindola | ba21024 | 2010-11-28 16:22:59 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 179 | void WinCOFFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) { |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 180 | llvm_unreachable("not implemented"); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Jim Grosbach | ce79299 | 2010-11-05 22:08:08 +0000 | [diff] [blame] | 183 | void WinCOFFStreamer::EmitThumbFunc(MCSymbol *Func) { |
| 184 | llvm_unreachable("not implemented"); |
| 185 | } |
| 186 | |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 187 | void WinCOFFStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) { |
Michael J. Spencer | d47f4a9 | 2010-10-09 11:00:37 +0000 | [diff] [blame] | 188 | assert((Symbol->isInSection() |
| 189 | ? Symbol->getSection().getVariant() == MCSection::SV_COFF |
| 190 | : true) && "Got non COFF section in the COFF backend!"); |
Michael J. Spencer | b5814a3 | 2010-10-07 06:29:33 +0000 | [diff] [blame] | 191 | // FIXME: This is all very ugly and depressing. What needs to happen here |
| 192 | // depends on quite a few things that are all part of relaxation, which we |
| 193 | // don't really even do. |
| 194 | |
| 195 | if (Value->getKind() != MCExpr::SymbolRef) { |
Eli Bendersky | cd81dce | 2012-12-07 17:55:28 +0000 | [diff] [blame^] | 196 | MCObjectStreamer::EmitAssignment(Symbol, Value); |
Michael J. Spencer | b5814a3 | 2010-10-07 06:29:33 +0000 | [diff] [blame] | 197 | } else { |
| 198 | // FIXME: This is a horrible way to do this :(. This should really be |
| 199 | // handled after we are done with the MC* objects and immediately before |
| 200 | // writing out the object file when we know exactly what the symbol should |
| 201 | // look like in the coff symbol table. I'm not doing that now because the |
| 202 | // COFF object writer doesn't have a clearly defined separation between MC |
| 203 | // data structures, the object writers data structures, and the raw, POD, |
| 204 | // data structures that get written to disk. |
| 205 | |
| 206 | // Copy over the aliased data. |
| 207 | MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); |
| 208 | const MCSymbolData &RealSD = getAssembler().getOrCreateSymbolData( |
| 209 | dyn_cast<const MCSymbolRefExpr>(Value)->getSymbol()); |
| 210 | |
| 211 | // FIXME: This is particularly nasty because it breaks as soon as any data |
| 212 | // members of MCSymbolData change. |
| 213 | SD.CommonAlign = RealSD.CommonAlign; |
| 214 | SD.CommonSize = RealSD.CommonSize; |
| 215 | SD.Flags = RealSD.Flags; |
| 216 | SD.Fragment = RealSD.Fragment; |
| 217 | SD.Index = RealSD.Index; |
| 218 | SD.IsExternal = RealSD.IsExternal; |
| 219 | SD.IsPrivateExtern = RealSD.IsPrivateExtern; |
| 220 | SD.Offset = RealSD.Offset; |
| 221 | SD.SymbolSize = RealSD.SymbolSize; |
| 222 | } |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | void WinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol, |
| 226 | MCSymbolAttr Attribute) { |
Michael J. Spencer | d47f4a9 | 2010-10-09 11:00:37 +0000 | [diff] [blame] | 227 | assert(Symbol && "Symbol must be non-null!"); |
| 228 | assert((Symbol->isInSection() |
| 229 | ? Symbol->getSection().getVariant() == MCSection::SV_COFF |
| 230 | : true) && "Got non COFF section in the COFF backend!"); |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 231 | switch (Attribute) { |
| 232 | case MCSA_WeakReference: |
Michael J. Spencer | 4cee289 | 2010-10-16 08:25:57 +0000 | [diff] [blame] | 233 | case MCSA_Weak: { |
| 234 | MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol); |
| 235 | SD.modifyFlags(COFF::SF_WeakExternal, COFF::SF_WeakExternal); |
| 236 | SD.setExternal(true); |
| 237 | } |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 238 | break; |
| 239 | |
| 240 | case MCSA_Global: |
| 241 | getAssembler().getOrCreateSymbolData(*Symbol).setExternal(true); |
| 242 | break; |
| 243 | |
| 244 | default: |
| 245 | llvm_unreachable("unsupported attribute"); |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 246 | } |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | void WinCOFFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) { |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 250 | llvm_unreachable("not implemented"); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | void WinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *Symbol) { |
Michael J. Spencer | d47f4a9 | 2010-10-09 11:00:37 +0000 | [diff] [blame] | 254 | assert((Symbol->isInSection() |
| 255 | ? Symbol->getSection().getVariant() == MCSection::SV_COFF |
| 256 | : true) && "Got non COFF section in the COFF backend!"); |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 257 | assert(CurSymbol == NULL && "EndCOFFSymbolDef must be called between calls " |
| 258 | "to BeginCOFFSymbolDef!"); |
| 259 | CurSymbol = Symbol; |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | void WinCOFFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) { |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 263 | assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!"); |
| 264 | assert((StorageClass & ~0xFF) == 0 && "StorageClass must only have data in " |
| 265 | "the first byte!"); |
| 266 | |
| 267 | getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags( |
| 268 | StorageClass << COFF::SF_ClassShift, |
| 269 | COFF::SF_ClassMask); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | void WinCOFFStreamer::EmitCOFFSymbolType(int Type) { |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 273 | assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!"); |
| 274 | assert((Type & ~0xFFFF) == 0 && "Type must only have data in the first 2 " |
| 275 | "bytes"); |
| 276 | |
| 277 | getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags( |
| 278 | Type << COFF::SF_TypeShift, |
| 279 | COFF::SF_TypeMask); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | void WinCOFFStreamer::EndCOFFSymbolDef() { |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 283 | assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!"); |
| 284 | CurSymbol = NULL; |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Rafael Espindola | 8f7d12c | 2011-12-17 01:14:52 +0000 | [diff] [blame] | 287 | void WinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) |
| 288 | { |
| 289 | MCDataFragment *DF = getOrCreateDataFragment(); |
| 290 | |
| 291 | DF->addFixup(MCFixup::Create(DF->getContents().size(), |
| 292 | MCSymbolRefExpr::Create (Symbol, getContext ()), |
Rafael Espindola | ce618af | 2011-12-24 14:47:52 +0000 | [diff] [blame] | 293 | FK_SecRel_4)); |
Rafael Espindola | 8f7d12c | 2011-12-17 01:14:52 +0000 | [diff] [blame] | 294 | DF->getContents().resize(DF->getContents().size() + 4, 0); |
| 295 | } |
| 296 | |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 297 | void WinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) { |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 298 | llvm_unreachable("not implemented"); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | void WinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 302 | unsigned ByteAlignment) { |
Michael J. Spencer | d47f4a9 | 2010-10-09 11:00:37 +0000 | [diff] [blame] | 303 | assert((Symbol->isInSection() |
| 304 | ? Symbol->getSection().getVariant() == MCSection::SV_COFF |
| 305 | : true) && "Got non COFF section in the COFF backend!"); |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 306 | AddCommonSymbol(Symbol, Size, ByteAlignment, true); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Benjamin Kramer | 36a1601 | 2011-09-01 23:04:27 +0000 | [diff] [blame] | 309 | void WinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
| 310 | unsigned ByteAlignment) { |
Michael J. Spencer | d47f4a9 | 2010-10-09 11:00:37 +0000 | [diff] [blame] | 311 | assert((Symbol->isInSection() |
| 312 | ? Symbol->getSection().getVariant() == MCSection::SV_COFF |
| 313 | : true) && "Got non COFF section in the COFF backend!"); |
Benjamin Kramer | 36a1601 | 2011-09-01 23:04:27 +0000 | [diff] [blame] | 314 | AddCommonSymbol(Symbol, Size, ByteAlignment, false); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void WinCOFFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol, |
Evan Cheng | c90a1fc | 2012-06-22 20:14:46 +0000 | [diff] [blame] | 318 | uint64_t Size,unsigned ByteAlignment) { |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 319 | llvm_unreachable("not implemented"); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | void WinCOFFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, |
| 323 | uint64_t Size, unsigned ByteAlignment) { |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 324 | llvm_unreachable("not implemented"); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 327 | void WinCOFFStreamer::EmitFileDirective(StringRef Filename) { |
| 328 | // Ignore for now, linkers don't care, and proper debug |
| 329 | // info will be a much large effort. |
| 330 | } |
| 331 | |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 332 | void WinCOFFStreamer::EmitInstruction(const MCInst &Instruction) { |
Michael J. Spencer | 8067adc | 2010-07-19 06:13:10 +0000 | [diff] [blame] | 333 | for (unsigned i = 0, e = Instruction.getNumOperands(); i != e; ++i) |
| 334 | if (Instruction.getOperand(i).isExpr()) |
| 335 | AddValueSymbols(Instruction.getOperand(i).getExpr()); |
| 336 | |
| 337 | getCurrentSectionData()->setHasInstructions(true); |
| 338 | |
| 339 | MCInstFragment *Fragment = |
| 340 | new MCInstFragment(Instruction, getCurrentSectionData()); |
| 341 | |
| 342 | raw_svector_ostream VecOS(Fragment->getCode()); |
| 343 | |
| 344 | getAssembler().getEmitter().EncodeInstruction(Instruction, VecOS, |
| 345 | Fragment->getFixups()); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Charles Davis | 3185f5c | 2011-05-22 03:01:05 +0000 | [diff] [blame] | 348 | void WinCOFFStreamer::EmitWin64EHHandlerData() { |
| 349 | MCStreamer::EmitWin64EHHandlerData(); |
| 350 | |
| 351 | // We have to emit the unwind info now, because this directive |
| 352 | // actually switches to the .xdata section! |
| 353 | MCWin64EHUnwindEmitter::EmitUnwindInfo(*this, getCurrentW64UnwindInfo()); |
| 354 | } |
| 355 | |
Rafael Espindola | 99b4237 | 2012-01-07 03:13:18 +0000 | [diff] [blame] | 356 | void WinCOFFStreamer::FinishImpl() { |
Charles Davis | 38ea9ee | 2011-05-22 04:15:07 +0000 | [diff] [blame] | 357 | EmitW64Tables(); |
Rafael Espindola | 99b4237 | 2012-01-07 03:13:18 +0000 | [diff] [blame] | 358 | MCObjectStreamer::FinishImpl(); |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | namespace llvm |
| 362 | { |
| 363 | MCStreamer *createWinCOFFStreamer(MCContext &Context, |
Evan Cheng | 78c10ee | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 364 | MCAsmBackend &MAB, |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 365 | MCCodeEmitter &CE, |
Michael J. Spencer | e2195d8 | 2010-07-31 06:22:29 +0000 | [diff] [blame] | 366 | raw_ostream &OS, |
| 367 | bool RelaxAll) { |
Evan Cheng | 78c10ee | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 368 | WinCOFFStreamer *S = new WinCOFFStreamer(Context, MAB, CE, OS); |
Michael J. Spencer | e2195d8 | 2010-07-31 06:22:29 +0000 | [diff] [blame] | 369 | S->getAssembler().setRelaxAll(RelaxAll); |
| 370 | return S; |
Chris Lattner | eb72dca | 2010-07-11 22:05:00 +0000 | [diff] [blame] | 371 | } |
| 372 | } |