blob: 9771ef0549c90f36301cb46ce5834746c9e07e11 [file] [log] [blame]
Matt Fleming3565a062010-08-16 18:57:57 +00001//===- lib/MC/MCELFStreamer.cpp - ELF Object Output ------------===//
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 assembles .s files and emits ELF .o object files.
11//
12//===----------------------------------------------------------------------===//
13
Logan Chien64501652012-12-07 15:50:40 +000014#include "llvm/MC/MCELFStreamer.h"
Rafael Espindolaf340a292012-01-07 23:18:39 +000015#include "llvm/ADT/SmallPtrSet.h"
16#include "llvm/MC/MCAssembler.h"
Matt Fleming3565a062010-08-16 18:57:57 +000017#include "llvm/MC/MCCodeEmitter.h"
Rafael Espindolaf340a292012-01-07 23:18:39 +000018#include "llvm/MC/MCContext.h"
Tim Northover6eb3e872012-12-07 16:50:23 +000019#include "llvm/MC/MCELF.h"
Matt Fleming3565a062010-08-16 18:57:57 +000020#include "llvm/MC/MCELFSymbolFlags.h"
21#include "llvm/MC/MCExpr.h"
22#include "llvm/MC/MCInst.h"
Rafael Espindolaf340a292012-01-07 23:18:39 +000023#include "llvm/MC/MCObjectStreamer.h"
Matt Fleming3565a062010-08-16 18:57:57 +000024#include "llvm/MC/MCSection.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000025#include "llvm/MC/MCSectionELF.h"
Matt Fleming3565a062010-08-16 18:57:57 +000026#include "llvm/MC/MCSymbol.h"
Rafael Espindola484291c2010-11-01 14:28:48 +000027#include "llvm/MC/MCValue.h"
Matt Fleming3565a062010-08-16 18:57:57 +000028#include "llvm/Support/Debug.h"
29#include "llvm/Support/ELF.h"
30#include "llvm/Support/ErrorHandling.h"
31#include "llvm/Support/raw_ostream.h"
Matt Fleming3565a062010-08-16 18:57:57 +000032
33using namespace llvm;
34
Rafael Espindolaf340a292012-01-07 23:18:39 +000035
Logan Chien64501652012-12-07 15:50:40 +000036inline void MCELFStreamer::SetSection(StringRef Section, unsigned Type,
37 unsigned Flags, SectionKind Kind) {
38 SwitchSection(getContext().getELFSection(Section, Type, Flags, Kind));
39}
Rafael Espindolaf340a292012-01-07 23:18:39 +000040
Logan Chien64501652012-12-07 15:50:40 +000041inline void MCELFStreamer::SetSectionData() {
42 SetSection(".data",
43 ELF::SHT_PROGBITS,
44 ELF::SHF_WRITE | ELF::SHF_ALLOC,
45 SectionKind::getDataRel());
46 EmitCodeAlignment(4, 0);
47}
Rafael Espindolaf340a292012-01-07 23:18:39 +000048
Logan Chien64501652012-12-07 15:50:40 +000049inline void MCELFStreamer::SetSectionText() {
50 SetSection(".text",
51 ELF::SHT_PROGBITS,
52 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC,
53 SectionKind::getText());
54 EmitCodeAlignment(4, 0);
55}
Rafael Espindolaf340a292012-01-07 23:18:39 +000056
Logan Chien64501652012-12-07 15:50:40 +000057inline void MCELFStreamer::SetSectionBss() {
58 SetSection(".bss",
59 ELF::SHT_NOBITS,
60 ELF::SHF_WRITE | ELF::SHF_ALLOC,
61 SectionKind::getBSS());
62 EmitCodeAlignment(4, 0);
63}
Rafael Espindolaf340a292012-01-07 23:18:39 +000064
Logan Chien64501652012-12-07 15:50:40 +000065MCELFStreamer::~MCELFStreamer() {
Rafael Espindolaf340a292012-01-07 23:18:39 +000066}
67
Rafael Espindolad80781b2010-09-15 21:48:40 +000068void MCELFStreamer::InitSections() {
69 // This emulates the same behavior of GNU as. This makes it easier
70 // to compare the output as the major sections are in the same order.
71 SetSectionText();
72 SetSectionData();
73 SetSectionBss();
74 SetSectionText();
75}
76
Matt Fleming3565a062010-08-16 18:57:57 +000077void MCELFStreamer::EmitLabel(MCSymbol *Symbol) {
Rafael Espindolaba210242010-11-28 16:22:59 +000078 assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
79
Rafael Espindolaea4afa92010-11-28 17:18:55 +000080 MCObjectStreamer::EmitLabel(Symbol);
Rafael Espindola73ffea42010-09-25 05:42:19 +000081
Rafael Espindolae1a25872010-11-11 19:04:55 +000082 const MCSectionELF &Section =
83 static_cast<const MCSectionELF&>(Symbol->getSection());
Rafael Espindolaea4afa92010-11-28 17:18:55 +000084 MCSymbolData &SD = getAssembler().getSymbolData(*Symbol);
Rafael Espindola1c130262011-01-23 04:43:11 +000085 if (Section.getFlags() & ELF::SHF_TLS)
Jan Sjödin2ddfd952011-02-28 21:45:04 +000086 MCELF::SetType(SD, ELF::STT_TLS);
Matt Fleming3565a062010-08-16 18:57:57 +000087}
88
Reed Kotler2c3a4642012-12-16 04:00:45 +000089void MCELFStreamer::EmitDebugLabel(MCSymbol *Symbol) {
90 EmitLabel(Symbol);
91}
92
Matt Fleming3565a062010-08-16 18:57:57 +000093void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
94 switch (Flag) {
Jim Grosbachce792992010-11-05 22:08:08 +000095 case MCAF_SyntaxUnified: return; // no-op here.
Evan Chengbd27f5a2011-07-27 00:38:12 +000096 case MCAF_Code16: return; // Change parsing mode; no-op here.
97 case MCAF_Code32: return; // Change parsing mode; no-op here.
98 case MCAF_Code64: return; // Change parsing mode; no-op here.
Matt Fleming3565a062010-08-16 18:57:57 +000099 case MCAF_SubsectionsViaSymbols:
100 getAssembler().setSubsectionsViaSymbols(true);
101 return;
102 }
103
Craig Topper85814382012-02-07 05:05:23 +0000104 llvm_unreachable("invalid assembler flag!");
Matt Fleming3565a062010-08-16 18:57:57 +0000105}
106
Rafael Espindola7768a9d2011-02-16 01:08:29 +0000107void MCELFStreamer::ChangeSection(const MCSection *Section) {
Rafael Espindola1f4f9e32010-11-14 04:17:37 +0000108 const MCSymbol *Grp = static_cast<const MCSectionELF *>(Section)->getGroup();
109 if (Grp)
110 getAssembler().getOrCreateSymbolData(*Grp);
Rafael Espindola7768a9d2011-02-16 01:08:29 +0000111 this->MCObjectStreamer::ChangeSection(Section);
Rafael Espindola1f4f9e32010-11-14 04:17:37 +0000112}
113
Rafael Espindola484291c2010-11-01 14:28:48 +0000114void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
115 getAssembler().getOrCreateSymbolData(*Symbol);
116 MCSymbolData &AliasSD = getAssembler().getOrCreateSymbolData(*Alias);
117 AliasSD.setFlags(AliasSD.getFlags() | ELF_Other_Weakref);
Rafael Espindola94ed5fc2010-11-15 16:33:49 +0000118 const MCExpr *Value = MCSymbolRefExpr::Create(Symbol, getContext());
Rafael Espindola484291c2010-11-01 14:28:48 +0000119 Alias->setVariableValue(Value);
120}
121
Matt Fleming3565a062010-08-16 18:57:57 +0000122void MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
123 MCSymbolAttr Attribute) {
124 // Indirect symbols are handled differently, to match how 'as' handles
125 // them. This makes writing matching .o files easier.
126 if (Attribute == MCSA_IndirectSymbol) {
127 // Note that we intentionally cannot use the symbol data here; this is
128 // important for matching the string table that 'as' generates.
129 IndirectSymbolData ISD;
130 ISD.Symbol = Symbol;
131 ISD.SectionData = getCurrentSectionData();
132 getAssembler().getIndirectSymbols().push_back(ISD);
133 return;
134 }
135
136 // Adding a symbol attribute always introduces the symbol, note that an
137 // important side effect of calling getOrCreateSymbolData here is to register
138 // the symbol with the assembler.
139 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
140
141 // The implementation of symbol attributes is designed to match 'as', but it
142 // leaves much to desired. It doesn't really make sense to arbitrarily add and
143 // remove flags, but 'as' allows this (in particular, see .desc).
144 //
145 // In the future it might be worth trying to make these operations more well
146 // defined.
147 switch (Attribute) {
148 case MCSA_LazyReference:
149 case MCSA_Reference:
Kevin Enderbye8e98d72010-11-19 18:39:33 +0000150 case MCSA_SymbolResolver:
Matt Fleming3565a062010-08-16 18:57:57 +0000151 case MCSA_PrivateExtern:
Matt Fleming3565a062010-08-16 18:57:57 +0000152 case MCSA_WeakDefinition:
Eli Friedmanf8020a32010-08-16 19:15:06 +0000153 case MCSA_WeakDefAutoPrivate:
Matt Fleming3565a062010-08-16 18:57:57 +0000154 case MCSA_Invalid:
Matt Fleming3565a062010-08-16 18:57:57 +0000155 case MCSA_IndirectSymbol:
Craig Topper85814382012-02-07 05:05:23 +0000156 llvm_unreachable("Invalid symbol attribute for ELF!");
Matt Fleming3565a062010-08-16 18:57:57 +0000157
Jim Grosbach3f90a4c2012-09-13 23:11:31 +0000158 case MCSA_NoDeadStrip:
Rafael Espindola7e528a12010-11-14 01:34:31 +0000159 case MCSA_ELF_TypeGnuUniqueObject:
160 // Ignore for now.
161 break;
162
Matt Fleming3565a062010-08-16 18:57:57 +0000163 case MCSA_Global:
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000164 MCELF::SetBinding(SD, ELF::STB_GLOBAL);
Matt Fleming3565a062010-08-16 18:57:57 +0000165 SD.setExternal(true);
Rafael Espindolaf7c10a32010-09-21 00:24:38 +0000166 BindingExplicitlySet.insert(Symbol);
Matt Fleming3565a062010-08-16 18:57:57 +0000167 break;
168
Benjamin Kramer230c2742010-09-02 17:18:32 +0000169 case MCSA_WeakReference:
Matt Fleming3565a062010-08-16 18:57:57 +0000170 case MCSA_Weak:
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000171 MCELF::SetBinding(SD, ELF::STB_WEAK);
Rafael Espindola3223f192010-10-06 16:47:31 +0000172 SD.setExternal(true);
Rafael Espindolaf7c10a32010-09-21 00:24:38 +0000173 BindingExplicitlySet.insert(Symbol);
Matt Fleming3565a062010-08-16 18:57:57 +0000174 break;
175
176 case MCSA_Local:
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000177 MCELF::SetBinding(SD, ELF::STB_LOCAL);
Rafael Espindolaf7c10a32010-09-21 00:24:38 +0000178 SD.setExternal(false);
179 BindingExplicitlySet.insert(Symbol);
Matt Fleming3565a062010-08-16 18:57:57 +0000180 break;
181
182 case MCSA_ELF_TypeFunction:
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000183 MCELF::SetType(SD, ELF::STT_FUNC);
Matt Fleming3565a062010-08-16 18:57:57 +0000184 break;
185
Roman Divackya0c17a42011-12-12 17:34:04 +0000186 case MCSA_ELF_TypeIndFunction:
187 MCELF::SetType(SD, ELF::STT_GNU_IFUNC);
188 break;
189
Matt Fleming3565a062010-08-16 18:57:57 +0000190 case MCSA_ELF_TypeObject:
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000191 MCELF::SetType(SD, ELF::STT_OBJECT);
Matt Fleming3565a062010-08-16 18:57:57 +0000192 break;
193
194 case MCSA_ELF_TypeTLS:
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000195 MCELF::SetType(SD, ELF::STT_TLS);
Matt Fleming3565a062010-08-16 18:57:57 +0000196 break;
197
198 case MCSA_ELF_TypeCommon:
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000199 MCELF::SetType(SD, ELF::STT_COMMON);
Matt Fleming3565a062010-08-16 18:57:57 +0000200 break;
201
202 case MCSA_ELF_TypeNoType:
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000203 MCELF::SetType(SD, ELF::STT_NOTYPE);
Matt Fleming3565a062010-08-16 18:57:57 +0000204 break;
205
206 case MCSA_Protected:
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000207 MCELF::SetVisibility(SD, ELF::STV_PROTECTED);
Matt Fleming3565a062010-08-16 18:57:57 +0000208 break;
209
210 case MCSA_Hidden:
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000211 MCELF::SetVisibility(SD, ELF::STV_HIDDEN);
Matt Fleming3565a062010-08-16 18:57:57 +0000212 break;
213
214 case MCSA_Internal:
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000215 MCELF::SetVisibility(SD, ELF::STV_INTERNAL);
Matt Fleming3565a062010-08-16 18:57:57 +0000216 break;
217 }
218}
219
220void MCELFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
221 unsigned ByteAlignment) {
222 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
223
Rafael Espindolaf7c10a32010-09-21 00:24:38 +0000224 if (!BindingExplicitlySet.count(Symbol)) {
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000225 MCELF::SetBinding(SD, ELF::STB_GLOBAL);
Rafael Espindolaf7c10a32010-09-21 00:24:38 +0000226 SD.setExternal(true);
227 }
228
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000229 MCELF::SetType(SD, ELF::STT_OBJECT);
Rafael Espindola55d02f32010-11-14 21:11:16 +0000230
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000231 if (MCELF::GetBinding(SD) == ELF_STB_Local) {
Matt Fleming3565a062010-08-16 18:57:57 +0000232 const MCSection *Section = getAssembler().getContext().getELFSection(".bss",
Jim Grosbach946227d2011-11-15 16:46:22 +0000233 ELF::SHT_NOBITS,
234 ELF::SHF_WRITE |
235 ELF::SHF_ALLOC,
236 SectionKind::getBSS());
Matt Fleming3565a062010-08-16 18:57:57 +0000237 Symbol->setSection(*Section);
Rafael Espindola19635722010-09-22 17:43:04 +0000238
Rafael Espindola9e3922e2010-09-29 14:52:01 +0000239 struct LocalCommon L = {&SD, Size, ByteAlignment};
240 LocalCommons.push_back(L);
Rafael Espindolaf7c10a32010-09-21 00:24:38 +0000241 } else {
242 SD.setCommon(Size, ByteAlignment);
Matt Fleming3565a062010-08-16 18:57:57 +0000243 }
244
Rafael Espindolaf7c10a32010-09-21 00:24:38 +0000245 SD.setSize(MCConstantExpr::Create(Size, getContext()));
Matt Fleming3565a062010-08-16 18:57:57 +0000246}
247
Logan Chien64501652012-12-07 15:50:40 +0000248void MCELFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
249 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
250 SD.setSize(Value);
251}
252
Benjamin Kramer36a16012011-09-01 23:04:27 +0000253void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
254 unsigned ByteAlignment) {
Jason W Kimf13743b2010-12-16 03:12:17 +0000255 // FIXME: Should this be caught and done earlier?
256 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000257 MCELF::SetBinding(SD, ELF::STB_LOCAL);
Jason W Kimf13743b2010-12-16 03:12:17 +0000258 SD.setExternal(false);
259 BindingExplicitlySet.insert(Symbol);
Benjamin Kramer36a16012011-09-01 23:04:27 +0000260 EmitCommonSymbol(Symbol, Size, ByteAlignment);
Jason W Kimf13743b2010-12-16 03:12:17 +0000261}
262
David Meyer5f769262012-02-15 15:09:06 +0000263void MCELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
264 unsigned AddrSpace) {
265 fixSymbolsInTLSFixups(Value);
266 MCObjectStreamer::EmitValueImpl(Value, Size, AddrSpace);
267}
268
269
Matt Fleming3565a062010-08-16 18:57:57 +0000270// Add a symbol for the file name of this module. This is the second
271// entry in the module's symbol table (the first being the null symbol).
272void MCELFStreamer::EmitFileDirective(StringRef Filename) {
273 MCSymbol *Symbol = getAssembler().getContext().GetOrCreateSymbol(Filename);
Rafael Espindola7768a9d2011-02-16 01:08:29 +0000274 Symbol->setSection(*getCurrentSection());
Matt Fleming3565a062010-08-16 18:57:57 +0000275 Symbol->setAbsolute();
276
277 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
278
279 SD.setFlags(ELF_STT_File | ELF_STB_Local | ELF_STV_Default);
280}
281
Rafael Espindola97551272010-11-24 02:19:40 +0000282void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
283 switch (expr->getKind()) {
284 case MCExpr::Target: llvm_unreachable("Can't handle target exprs yet!");
285 case MCExpr::Constant:
286 break;
287
288 case MCExpr::Binary: {
289 const MCBinaryExpr *be = cast<MCBinaryExpr>(expr);
290 fixSymbolsInTLSFixups(be->getLHS());
291 fixSymbolsInTLSFixups(be->getRHS());
292 break;
293 }
294
295 case MCExpr::SymbolRef: {
296 const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr);
Rafael Espindolabf8209d2010-11-24 18:51:21 +0000297 switch (symRef.getKind()) {
298 default:
Rafael Espindola97551272010-11-24 02:19:40 +0000299 return;
Joerg Sonnenbergerd02c8b62011-03-17 00:35:10 +0000300 case MCSymbolRefExpr::VK_GOTTPOFF:
301 case MCSymbolRefExpr::VK_INDNTPOFF:
Rafael Espindolabf8209d2010-11-24 18:51:21 +0000302 case MCSymbolRefExpr::VK_NTPOFF:
303 case MCSymbolRefExpr::VK_GOTNTPOFF:
304 case MCSymbolRefExpr::VK_TLSGD:
Joerg Sonnenbergerd02c8b62011-03-17 00:35:10 +0000305 case MCSymbolRefExpr::VK_TLSLD:
Rafael Espindolabf8209d2010-11-24 18:51:21 +0000306 case MCSymbolRefExpr::VK_TLSLDM:
307 case MCSymbolRefExpr::VK_TPOFF:
308 case MCSymbolRefExpr::VK_DTPOFF:
Rafael Espindolabf8209d2010-11-24 18:51:21 +0000309 case MCSymbolRefExpr::VK_ARM_TLSGD:
Joerg Sonnenbergerd02c8b62011-03-17 00:35:10 +0000310 case MCSymbolRefExpr::VK_ARM_TPOFF:
311 case MCSymbolRefExpr::VK_ARM_GOTTPOFF:
Bruno Cardoso Lopes3507d242011-10-25 18:13:20 +0000312 case MCSymbolRefExpr::VK_Mips_TLSGD:
313 case MCSymbolRefExpr::VK_Mips_GOTTPREL:
314 case MCSymbolRefExpr::VK_Mips_TPREL_HI:
315 case MCSymbolRefExpr::VK_Mips_TPREL_LO:
Rafael Espindolabf8209d2010-11-24 18:51:21 +0000316 break;
317 }
Rafael Espindola97551272010-11-24 02:19:40 +0000318 MCSymbolData &SD = getAssembler().getOrCreateSymbolData(symRef.getSymbol());
Jan Sjödin2ddfd952011-02-28 21:45:04 +0000319 MCELF::SetType(SD, ELF::STT_TLS);
Rafael Espindola97551272010-11-24 02:19:40 +0000320 break;
321 }
322
323 case MCExpr::Unary:
324 fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
325 break;
326 }
327}
328
Benjamin Kramer93ded732010-08-27 10:40:51 +0000329void MCELFStreamer::EmitInstToFragment(const MCInst &Inst) {
Rafael Espindoladedb0452010-12-02 05:44:06 +0000330 this->MCObjectStreamer::EmitInstToFragment(Inst);
331 MCInstFragment &F = *cast<MCInstFragment>(getCurrentFragment());
Benjamin Kramer93ded732010-08-27 10:40:51 +0000332
Rafael Espindoladedb0452010-12-02 05:44:06 +0000333 for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
334 fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
Benjamin Kramer93ded732010-08-27 10:40:51 +0000335}
336
337void MCELFStreamer::EmitInstToData(const MCInst &Inst) {
338 MCDataFragment *DF = getOrCreateDataFragment();
339
340 SmallVector<MCFixup, 4> Fixups;
341 SmallString<256> Code;
342 raw_svector_ostream VecOS(Code);
343 getAssembler().getEmitter().EncodeInstruction(Inst, VecOS, Fixups);
344 VecOS.flush();
345
Rafael Espindola97551272010-11-24 02:19:40 +0000346 for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
347 fixSymbolsInTLSFixups(Fixups[i].getValue());
348
Benjamin Kramer93ded732010-08-27 10:40:51 +0000349 // Add the fixups and data.
350 for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
351 Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
Eli Bendersky64d9a322012-12-07 19:13:57 +0000352 DF->getFixups().push_back(Fixups[i]);
Benjamin Kramer93ded732010-08-27 10:40:51 +0000353 }
354 DF->getContents().append(Code.begin(), Code.end());
355}
356
Rafael Espindola99b42372012-01-07 03:13:18 +0000357void MCELFStreamer::FinishImpl() {
Rafael Espindolac25dad82011-05-10 03:14:15 +0000358 EmitFrames(true);
Rafael Espindolac70a1d92010-11-01 17:07:14 +0000359
Rafael Espindola9e3922e2010-09-29 14:52:01 +0000360 for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),
361 e = LocalCommons.end();
362 i != e; ++i) {
363 MCSymbolData *SD = i->SD;
364 uint64_t Size = i->Size;
365 unsigned ByteAlignment = i->ByteAlignment;
366 const MCSymbol &Symbol = SD->getSymbol();
367 const MCSection &Section = Symbol.getSection();
368
369 MCSectionData &SectData = getAssembler().getOrCreateSectionData(Section);
370 new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &SectData);
371
372 MCFragment *F = new MCFillFragment(0, 0, Size, &SectData);
373 SD->setFragment(F);
374
375 // Update the maximum alignment of the section if necessary.
376 if (ByteAlignment > SectData.getAlignment())
377 SectData.setAlignment(ByteAlignment);
378 }
379
Rafael Espindola99b42372012-01-07 03:13:18 +0000380 this->MCObjectStreamer::FinishImpl();
Matt Fleming3565a062010-08-16 18:57:57 +0000381}
Tim Northover6eb3e872012-12-07 16:50:23 +0000382void MCELFStreamer::EmitTCEntry(const MCSymbol &S) {
Adhemerval Zanellaf35c62b2012-10-15 15:43:14 +0000383 // Creates a R_PPC64_TOC relocation
384 MCObjectStreamer::EmitSymbolValue(&S, 8, 0);
385}
386
Evan Cheng78c10ee2011-07-25 23:24:55 +0000387MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB,
Rafael Espindola96aa78c2011-01-23 17:55:27 +0000388 raw_ostream &OS, MCCodeEmitter *CE,
389 bool RelaxAll, bool NoExecStack) {
Evan Cheng78c10ee2011-07-25 23:24:55 +0000390 MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE);
Matt Fleming3565a062010-08-16 18:57:57 +0000391 if (RelaxAll)
392 S->getAssembler().setRelaxAll(true);
Rafael Espindola96aa78c2011-01-23 17:55:27 +0000393 if (NoExecStack)
394 S->getAssembler().setNoExecStack(true);
Matt Fleming3565a062010-08-16 18:57:57 +0000395 return S;
396}
Logan Chien64501652012-12-07 15:50:40 +0000397
Tim Northover6eb3e872012-12-07 16:50:23 +0000398void MCELFStreamer::EmitThumbFunc(MCSymbol *Func) {
399 llvm_unreachable("Generic ELF doesn't support this directive");
400}
401
Logan Chien64501652012-12-07 15:50:40 +0000402void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
403 llvm_unreachable("ELF doesn't support this directive");
404}
405
406void MCELFStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
407 llvm_unreachable("ELF doesn't support this directive");
408}
409
410void MCELFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
411 llvm_unreachable("ELF doesn't support this directive");
412}
413
414void MCELFStreamer::EmitCOFFSymbolType(int Type) {
415 llvm_unreachable("ELF doesn't support this directive");
416}
417
418void MCELFStreamer::EndCOFFSymbolDef() {
419 llvm_unreachable("ELF doesn't support this directive");
420}
421
422void MCELFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
423 uint64_t Size, unsigned ByteAlignment) {
424 llvm_unreachable("ELF doesn't support this directive");
425}
426
427void MCELFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
428 uint64_t Size, unsigned ByteAlignment) {
429 llvm_unreachable("ELF doesn't support this directive");
430}