xref: /minix3/external/bsd/llvm/dist/llvm/lib/MC/MCELFStreamer.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc //===- lib/MC/MCELFStreamer.cpp - ELF Object Output -----------------------===//
2*f4a2713aSLionel Sambuc //
3*f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*f4a2713aSLionel Sambuc //
5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7*f4a2713aSLionel Sambuc //
8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9*f4a2713aSLionel Sambuc //
10*f4a2713aSLionel Sambuc // This file assembles .s files and emits ELF .o object files.
11*f4a2713aSLionel Sambuc //
12*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc #include "llvm/MC/MCELFStreamer.h"
15*f4a2713aSLionel Sambuc #include "llvm/ADT/SmallPtrSet.h"
16*f4a2713aSLionel Sambuc #include "llvm/ADT/STLExtras.h"
17*f4a2713aSLionel Sambuc #include "llvm/MC/MCAssembler.h"
18*f4a2713aSLionel Sambuc #include "llvm/MC/MCCodeEmitter.h"
19*f4a2713aSLionel Sambuc #include "llvm/MC/MCContext.h"
20*f4a2713aSLionel Sambuc #include "llvm/MC/MCELF.h"
21*f4a2713aSLionel Sambuc #include "llvm/MC/MCELFSymbolFlags.h"
22*f4a2713aSLionel Sambuc #include "llvm/MC/MCExpr.h"
23*f4a2713aSLionel Sambuc #include "llvm/MC/MCInst.h"
24*f4a2713aSLionel Sambuc #include "llvm/MC/MCObjectStreamer.h"
25*f4a2713aSLionel Sambuc #include "llvm/MC/MCSection.h"
26*f4a2713aSLionel Sambuc #include "llvm/MC/MCSectionELF.h"
27*f4a2713aSLionel Sambuc #include "llvm/MC/MCSymbol.h"
28*f4a2713aSLionel Sambuc #include "llvm/MC/MCValue.h"
29*f4a2713aSLionel Sambuc #include "llvm/Support/Debug.h"
30*f4a2713aSLionel Sambuc #include "llvm/Support/ELF.h"
31*f4a2713aSLionel Sambuc #include "llvm/Support/ErrorHandling.h"
32*f4a2713aSLionel Sambuc #include "llvm/Support/raw_ostream.h"
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc using namespace llvm;
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc inline void MCELFStreamer::SetSection(StringRef Section, unsigned Type,
38*f4a2713aSLionel Sambuc                                       unsigned Flags, SectionKind Kind) {
39*f4a2713aSLionel Sambuc   SwitchSection(getContext().getELFSection(Section, Type, Flags, Kind));
40*f4a2713aSLionel Sambuc }
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc inline void MCELFStreamer::SetSectionData() {
43*f4a2713aSLionel Sambuc   SetSection(".data",
44*f4a2713aSLionel Sambuc              ELF::SHT_PROGBITS,
45*f4a2713aSLionel Sambuc              ELF::SHF_WRITE | ELF::SHF_ALLOC,
46*f4a2713aSLionel Sambuc              SectionKind::getDataRel());
47*f4a2713aSLionel Sambuc   EmitCodeAlignment(4, 0);
48*f4a2713aSLionel Sambuc }
49*f4a2713aSLionel Sambuc 
50*f4a2713aSLionel Sambuc inline void MCELFStreamer::SetSectionText() {
51*f4a2713aSLionel Sambuc   SetSection(".text",
52*f4a2713aSLionel Sambuc              ELF::SHT_PROGBITS,
53*f4a2713aSLionel Sambuc              ELF::SHF_EXECINSTR | ELF::SHF_ALLOC,
54*f4a2713aSLionel Sambuc              SectionKind::getText());
55*f4a2713aSLionel Sambuc   EmitCodeAlignment(4, 0);
56*f4a2713aSLionel Sambuc }
57*f4a2713aSLionel Sambuc 
58*f4a2713aSLionel Sambuc inline void MCELFStreamer::SetSectionBss() {
59*f4a2713aSLionel Sambuc   SetSection(".bss",
60*f4a2713aSLionel Sambuc              ELF::SHT_NOBITS,
61*f4a2713aSLionel Sambuc              ELF::SHF_WRITE | ELF::SHF_ALLOC,
62*f4a2713aSLionel Sambuc              SectionKind::getBSS());
63*f4a2713aSLionel Sambuc   EmitCodeAlignment(4, 0);
64*f4a2713aSLionel Sambuc }
65*f4a2713aSLionel Sambuc 
66*f4a2713aSLionel Sambuc MCELFStreamer::~MCELFStreamer() {
67*f4a2713aSLionel Sambuc }
68*f4a2713aSLionel Sambuc 
69*f4a2713aSLionel Sambuc void MCELFStreamer::InitToTextSection() {
70*f4a2713aSLionel Sambuc   SetSectionText();
71*f4a2713aSLionel Sambuc }
72*f4a2713aSLionel Sambuc 
73*f4a2713aSLionel Sambuc void MCELFStreamer::InitSections() {
74*f4a2713aSLionel Sambuc   // This emulates the same behavior of GNU as. This makes it easier
75*f4a2713aSLionel Sambuc   // to compare the output as the major sections are in the same order.
76*f4a2713aSLionel Sambuc   SetSectionText();
77*f4a2713aSLionel Sambuc   SetSectionData();
78*f4a2713aSLionel Sambuc   SetSectionBss();
79*f4a2713aSLionel Sambuc   SetSectionText();
80*f4a2713aSLionel Sambuc }
81*f4a2713aSLionel Sambuc 
82*f4a2713aSLionel Sambuc void MCELFStreamer::EmitLabel(MCSymbol *Symbol) {
83*f4a2713aSLionel Sambuc   assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
84*f4a2713aSLionel Sambuc 
85*f4a2713aSLionel Sambuc   MCObjectStreamer::EmitLabel(Symbol);
86*f4a2713aSLionel Sambuc 
87*f4a2713aSLionel Sambuc   const MCSectionELF &Section =
88*f4a2713aSLionel Sambuc     static_cast<const MCSectionELF&>(Symbol->getSection());
89*f4a2713aSLionel Sambuc   MCSymbolData &SD = getAssembler().getSymbolData(*Symbol);
90*f4a2713aSLionel Sambuc   if (Section.getFlags() & ELF::SHF_TLS)
91*f4a2713aSLionel Sambuc     MCELF::SetType(SD, ELF::STT_TLS);
92*f4a2713aSLionel Sambuc }
93*f4a2713aSLionel Sambuc 
94*f4a2713aSLionel Sambuc void MCELFStreamer::EmitDebugLabel(MCSymbol *Symbol) {
95*f4a2713aSLionel Sambuc   EmitLabel(Symbol);
96*f4a2713aSLionel Sambuc }
97*f4a2713aSLionel Sambuc 
98*f4a2713aSLionel Sambuc void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
99*f4a2713aSLionel Sambuc   switch (Flag) {
100*f4a2713aSLionel Sambuc   case MCAF_SyntaxUnified: return; // no-op here.
101*f4a2713aSLionel Sambuc   case MCAF_Code16: return; // Change parsing mode; no-op here.
102*f4a2713aSLionel Sambuc   case MCAF_Code32: return; // Change parsing mode; no-op here.
103*f4a2713aSLionel Sambuc   case MCAF_Code64: return; // Change parsing mode; no-op here.
104*f4a2713aSLionel Sambuc   case MCAF_SubsectionsViaSymbols:
105*f4a2713aSLionel Sambuc     getAssembler().setSubsectionsViaSymbols(true);
106*f4a2713aSLionel Sambuc     return;
107*f4a2713aSLionel Sambuc   }
108*f4a2713aSLionel Sambuc 
109*f4a2713aSLionel Sambuc   llvm_unreachable("invalid assembler flag!");
110*f4a2713aSLionel Sambuc }
111*f4a2713aSLionel Sambuc 
112*f4a2713aSLionel Sambuc void MCELFStreamer::ChangeSection(const MCSection *Section,
113*f4a2713aSLionel Sambuc                                   const MCExpr *Subsection) {
114*f4a2713aSLionel Sambuc   MCSectionData *CurSection = getCurrentSectionData();
115*f4a2713aSLionel Sambuc   if (CurSection && CurSection->isBundleLocked())
116*f4a2713aSLionel Sambuc     report_fatal_error("Unterminated .bundle_lock when changing a section");
117*f4a2713aSLionel Sambuc   const MCSymbol *Grp = static_cast<const MCSectionELF *>(Section)->getGroup();
118*f4a2713aSLionel Sambuc   if (Grp)
119*f4a2713aSLionel Sambuc     getAssembler().getOrCreateSymbolData(*Grp);
120*f4a2713aSLionel Sambuc   this->MCObjectStreamer::ChangeSection(Section, Subsection);
121*f4a2713aSLionel Sambuc }
122*f4a2713aSLionel Sambuc 
123*f4a2713aSLionel Sambuc void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
124*f4a2713aSLionel Sambuc   getAssembler().getOrCreateSymbolData(*Symbol);
125*f4a2713aSLionel Sambuc   MCSymbolData &AliasSD = getAssembler().getOrCreateSymbolData(*Alias);
126*f4a2713aSLionel Sambuc   AliasSD.setFlags(AliasSD.getFlags() | ELF_Other_Weakref);
127*f4a2713aSLionel Sambuc   const MCExpr *Value = MCSymbolRefExpr::Create(Symbol, getContext());
128*f4a2713aSLionel Sambuc   Alias->setVariableValue(Value);
129*f4a2713aSLionel Sambuc }
130*f4a2713aSLionel Sambuc 
131*f4a2713aSLionel Sambuc // When GNU as encounters more than one .type declaration for an object it seems
132*f4a2713aSLionel Sambuc // to use a mechanism similar to the one below to decide which type is actually
133*f4a2713aSLionel Sambuc // used in the object file.  The greater of T1 and T2 is selected based on the
134*f4a2713aSLionel Sambuc // following ordering:
135*f4a2713aSLionel Sambuc //  STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
136*f4a2713aSLionel Sambuc // If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
137*f4a2713aSLionel Sambuc // provided type).
138*f4a2713aSLionel Sambuc static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
139*f4a2713aSLionel Sambuc   unsigned TypeOrdering[] = {ELF::STT_NOTYPE, ELF::STT_OBJECT, ELF::STT_FUNC,
140*f4a2713aSLionel Sambuc                              ELF::STT_GNU_IFUNC, ELF::STT_TLS};
141*f4a2713aSLionel Sambuc   for (unsigned i = 0; i != array_lengthof(TypeOrdering); ++i) {
142*f4a2713aSLionel Sambuc     if (T1 == TypeOrdering[i])
143*f4a2713aSLionel Sambuc       return T2;
144*f4a2713aSLionel Sambuc     if (T2 == TypeOrdering[i])
145*f4a2713aSLionel Sambuc       return T1;
146*f4a2713aSLionel Sambuc   }
147*f4a2713aSLionel Sambuc 
148*f4a2713aSLionel Sambuc   return T2;
149*f4a2713aSLionel Sambuc }
150*f4a2713aSLionel Sambuc 
151*f4a2713aSLionel Sambuc bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
152*f4a2713aSLionel Sambuc                                         MCSymbolAttr Attribute) {
153*f4a2713aSLionel Sambuc   // Indirect symbols are handled differently, to match how 'as' handles
154*f4a2713aSLionel Sambuc   // them. This makes writing matching .o files easier.
155*f4a2713aSLionel Sambuc   if (Attribute == MCSA_IndirectSymbol) {
156*f4a2713aSLionel Sambuc     // Note that we intentionally cannot use the symbol data here; this is
157*f4a2713aSLionel Sambuc     // important for matching the string table that 'as' generates.
158*f4a2713aSLionel Sambuc     IndirectSymbolData ISD;
159*f4a2713aSLionel Sambuc     ISD.Symbol = Symbol;
160*f4a2713aSLionel Sambuc     ISD.SectionData = getCurrentSectionData();
161*f4a2713aSLionel Sambuc     getAssembler().getIndirectSymbols().push_back(ISD);
162*f4a2713aSLionel Sambuc     return true;
163*f4a2713aSLionel Sambuc   }
164*f4a2713aSLionel Sambuc 
165*f4a2713aSLionel Sambuc   // Adding a symbol attribute always introduces the symbol, note that an
166*f4a2713aSLionel Sambuc   // important side effect of calling getOrCreateSymbolData here is to register
167*f4a2713aSLionel Sambuc   // the symbol with the assembler.
168*f4a2713aSLionel Sambuc   MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
169*f4a2713aSLionel Sambuc 
170*f4a2713aSLionel Sambuc   // The implementation of symbol attributes is designed to match 'as', but it
171*f4a2713aSLionel Sambuc   // leaves much to desired. It doesn't really make sense to arbitrarily add and
172*f4a2713aSLionel Sambuc   // remove flags, but 'as' allows this (in particular, see .desc).
173*f4a2713aSLionel Sambuc   //
174*f4a2713aSLionel Sambuc   // In the future it might be worth trying to make these operations more well
175*f4a2713aSLionel Sambuc   // defined.
176*f4a2713aSLionel Sambuc   switch (Attribute) {
177*f4a2713aSLionel Sambuc   case MCSA_LazyReference:
178*f4a2713aSLionel Sambuc   case MCSA_Reference:
179*f4a2713aSLionel Sambuc   case MCSA_SymbolResolver:
180*f4a2713aSLionel Sambuc   case MCSA_PrivateExtern:
181*f4a2713aSLionel Sambuc   case MCSA_WeakDefinition:
182*f4a2713aSLionel Sambuc   case MCSA_WeakDefAutoPrivate:
183*f4a2713aSLionel Sambuc   case MCSA_Invalid:
184*f4a2713aSLionel Sambuc   case MCSA_IndirectSymbol:
185*f4a2713aSLionel Sambuc     return false;
186*f4a2713aSLionel Sambuc 
187*f4a2713aSLionel Sambuc   case MCSA_NoDeadStrip:
188*f4a2713aSLionel Sambuc   case MCSA_ELF_TypeGnuUniqueObject:
189*f4a2713aSLionel Sambuc     // Ignore for now.
190*f4a2713aSLionel Sambuc     break;
191*f4a2713aSLionel Sambuc 
192*f4a2713aSLionel Sambuc   case MCSA_Global:
193*f4a2713aSLionel Sambuc     MCELF::SetBinding(SD, ELF::STB_GLOBAL);
194*f4a2713aSLionel Sambuc     SD.setExternal(true);
195*f4a2713aSLionel Sambuc     BindingExplicitlySet.insert(Symbol);
196*f4a2713aSLionel Sambuc     break;
197*f4a2713aSLionel Sambuc 
198*f4a2713aSLionel Sambuc   case MCSA_WeakReference:
199*f4a2713aSLionel Sambuc   case MCSA_Weak:
200*f4a2713aSLionel Sambuc     MCELF::SetBinding(SD, ELF::STB_WEAK);
201*f4a2713aSLionel Sambuc     SD.setExternal(true);
202*f4a2713aSLionel Sambuc     BindingExplicitlySet.insert(Symbol);
203*f4a2713aSLionel Sambuc     break;
204*f4a2713aSLionel Sambuc 
205*f4a2713aSLionel Sambuc   case MCSA_Local:
206*f4a2713aSLionel Sambuc     MCELF::SetBinding(SD, ELF::STB_LOCAL);
207*f4a2713aSLionel Sambuc     SD.setExternal(false);
208*f4a2713aSLionel Sambuc     BindingExplicitlySet.insert(Symbol);
209*f4a2713aSLionel Sambuc     break;
210*f4a2713aSLionel Sambuc 
211*f4a2713aSLionel Sambuc   case MCSA_ELF_TypeFunction:
212*f4a2713aSLionel Sambuc     MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
213*f4a2713aSLionel Sambuc                                           ELF::STT_FUNC));
214*f4a2713aSLionel Sambuc     break;
215*f4a2713aSLionel Sambuc 
216*f4a2713aSLionel Sambuc   case MCSA_ELF_TypeIndFunction:
217*f4a2713aSLionel Sambuc     MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
218*f4a2713aSLionel Sambuc                                           ELF::STT_GNU_IFUNC));
219*f4a2713aSLionel Sambuc     break;
220*f4a2713aSLionel Sambuc 
221*f4a2713aSLionel Sambuc   case MCSA_ELF_TypeObject:
222*f4a2713aSLionel Sambuc     MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
223*f4a2713aSLionel Sambuc                                           ELF::STT_OBJECT));
224*f4a2713aSLionel Sambuc     break;
225*f4a2713aSLionel Sambuc 
226*f4a2713aSLionel Sambuc   case MCSA_ELF_TypeTLS:
227*f4a2713aSLionel Sambuc     MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
228*f4a2713aSLionel Sambuc                                           ELF::STT_TLS));
229*f4a2713aSLionel Sambuc     break;
230*f4a2713aSLionel Sambuc 
231*f4a2713aSLionel Sambuc   case MCSA_ELF_TypeCommon:
232*f4a2713aSLionel Sambuc     // TODO: Emit these as a common symbol.
233*f4a2713aSLionel Sambuc     MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
234*f4a2713aSLionel Sambuc                                           ELF::STT_OBJECT));
235*f4a2713aSLionel Sambuc     break;
236*f4a2713aSLionel Sambuc 
237*f4a2713aSLionel Sambuc   case MCSA_ELF_TypeNoType:
238*f4a2713aSLionel Sambuc     MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD),
239*f4a2713aSLionel Sambuc                                           ELF::STT_NOTYPE));
240*f4a2713aSLionel Sambuc     break;
241*f4a2713aSLionel Sambuc 
242*f4a2713aSLionel Sambuc   case MCSA_Protected:
243*f4a2713aSLionel Sambuc     MCELF::SetVisibility(SD, ELF::STV_PROTECTED);
244*f4a2713aSLionel Sambuc     break;
245*f4a2713aSLionel Sambuc 
246*f4a2713aSLionel Sambuc   case MCSA_Hidden:
247*f4a2713aSLionel Sambuc     MCELF::SetVisibility(SD, ELF::STV_HIDDEN);
248*f4a2713aSLionel Sambuc     break;
249*f4a2713aSLionel Sambuc 
250*f4a2713aSLionel Sambuc   case MCSA_Internal:
251*f4a2713aSLionel Sambuc     MCELF::SetVisibility(SD, ELF::STV_INTERNAL);
252*f4a2713aSLionel Sambuc     break;
253*f4a2713aSLionel Sambuc   }
254*f4a2713aSLionel Sambuc 
255*f4a2713aSLionel Sambuc   return true;
256*f4a2713aSLionel Sambuc }
257*f4a2713aSLionel Sambuc 
258*f4a2713aSLionel Sambuc void MCELFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
259*f4a2713aSLionel Sambuc                                        unsigned ByteAlignment) {
260*f4a2713aSLionel Sambuc   MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
261*f4a2713aSLionel Sambuc 
262*f4a2713aSLionel Sambuc   if (!BindingExplicitlySet.count(Symbol)) {
263*f4a2713aSLionel Sambuc     MCELF::SetBinding(SD, ELF::STB_GLOBAL);
264*f4a2713aSLionel Sambuc     SD.setExternal(true);
265*f4a2713aSLionel Sambuc   }
266*f4a2713aSLionel Sambuc 
267*f4a2713aSLionel Sambuc   MCELF::SetType(SD, ELF::STT_OBJECT);
268*f4a2713aSLionel Sambuc 
269*f4a2713aSLionel Sambuc   if (MCELF::GetBinding(SD) == ELF_STB_Local) {
270*f4a2713aSLionel Sambuc     const MCSection *Section = getAssembler().getContext().getELFSection(".bss",
271*f4a2713aSLionel Sambuc                                                          ELF::SHT_NOBITS,
272*f4a2713aSLionel Sambuc                                                          ELF::SHF_WRITE |
273*f4a2713aSLionel Sambuc                                                          ELF::SHF_ALLOC,
274*f4a2713aSLionel Sambuc                                                          SectionKind::getBSS());
275*f4a2713aSLionel Sambuc 
276*f4a2713aSLionel Sambuc     AssignSection(Symbol, Section);
277*f4a2713aSLionel Sambuc 
278*f4a2713aSLionel Sambuc     struct LocalCommon L = {&SD, Size, ByteAlignment};
279*f4a2713aSLionel Sambuc     LocalCommons.push_back(L);
280*f4a2713aSLionel Sambuc   } else {
281*f4a2713aSLionel Sambuc     SD.setCommon(Size, ByteAlignment);
282*f4a2713aSLionel Sambuc   }
283*f4a2713aSLionel Sambuc 
284*f4a2713aSLionel Sambuc   SD.setSize(MCConstantExpr::Create(Size, getContext()));
285*f4a2713aSLionel Sambuc }
286*f4a2713aSLionel Sambuc 
287*f4a2713aSLionel Sambuc void MCELFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
288*f4a2713aSLionel Sambuc   MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
289*f4a2713aSLionel Sambuc   SD.setSize(Value);
290*f4a2713aSLionel Sambuc }
291*f4a2713aSLionel Sambuc 
292*f4a2713aSLionel Sambuc void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
293*f4a2713aSLionel Sambuc                                           unsigned ByteAlignment) {
294*f4a2713aSLionel Sambuc   // FIXME: Should this be caught and done earlier?
295*f4a2713aSLionel Sambuc   MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
296*f4a2713aSLionel Sambuc   MCELF::SetBinding(SD, ELF::STB_LOCAL);
297*f4a2713aSLionel Sambuc   SD.setExternal(false);
298*f4a2713aSLionel Sambuc   BindingExplicitlySet.insert(Symbol);
299*f4a2713aSLionel Sambuc   EmitCommonSymbol(Symbol, Size, ByteAlignment);
300*f4a2713aSLionel Sambuc }
301*f4a2713aSLionel Sambuc 
302*f4a2713aSLionel Sambuc void MCELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size) {
303*f4a2713aSLionel Sambuc   if (getCurrentSectionData()->isBundleLocked())
304*f4a2713aSLionel Sambuc     report_fatal_error("Emitting values inside a locked bundle is forbidden");
305*f4a2713aSLionel Sambuc   fixSymbolsInTLSFixups(Value);
306*f4a2713aSLionel Sambuc   MCObjectStreamer::EmitValueImpl(Value, Size);
307*f4a2713aSLionel Sambuc }
308*f4a2713aSLionel Sambuc 
309*f4a2713aSLionel Sambuc void MCELFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
310*f4a2713aSLionel Sambuc                                          int64_t Value,
311*f4a2713aSLionel Sambuc                                          unsigned ValueSize,
312*f4a2713aSLionel Sambuc                                          unsigned MaxBytesToEmit) {
313*f4a2713aSLionel Sambuc   if (getCurrentSectionData()->isBundleLocked())
314*f4a2713aSLionel Sambuc     report_fatal_error("Emitting values inside a locked bundle is forbidden");
315*f4a2713aSLionel Sambuc   MCObjectStreamer::EmitValueToAlignment(ByteAlignment, Value,
316*f4a2713aSLionel Sambuc                                          ValueSize, MaxBytesToEmit);
317*f4a2713aSLionel Sambuc }
318*f4a2713aSLionel Sambuc 
319*f4a2713aSLionel Sambuc // Add a symbol for the file name of this module. They start after the
320*f4a2713aSLionel Sambuc // null symbol and don't count as normal symbol, i.e. a non-STT_FILE symbol
321*f4a2713aSLionel Sambuc // with the same name may appear.
322*f4a2713aSLionel Sambuc void MCELFStreamer::EmitFileDirective(StringRef Filename) {
323*f4a2713aSLionel Sambuc   getAssembler().addFileName(Filename);
324*f4a2713aSLionel Sambuc }
325*f4a2713aSLionel Sambuc 
326*f4a2713aSLionel Sambuc void MCELFStreamer::EmitIdent(StringRef IdentString) {
327*f4a2713aSLionel Sambuc   const MCSection *Comment = getAssembler().getContext().getELFSection(
328*f4a2713aSLionel Sambuc       ".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS,
329*f4a2713aSLionel Sambuc       SectionKind::getReadOnly(), 1, "");
330*f4a2713aSLionel Sambuc   PushSection();
331*f4a2713aSLionel Sambuc   SwitchSection(Comment);
332*f4a2713aSLionel Sambuc   if (!SeenIdent) {
333*f4a2713aSLionel Sambuc     EmitIntValue(0, 1);
334*f4a2713aSLionel Sambuc     SeenIdent = true;
335*f4a2713aSLionel Sambuc   }
336*f4a2713aSLionel Sambuc   EmitBytes(IdentString);
337*f4a2713aSLionel Sambuc   EmitIntValue(0, 1);
338*f4a2713aSLionel Sambuc   PopSection();
339*f4a2713aSLionel Sambuc }
340*f4a2713aSLionel Sambuc 
341*f4a2713aSLionel Sambuc void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
342*f4a2713aSLionel Sambuc   switch (expr->getKind()) {
343*f4a2713aSLionel Sambuc   case MCExpr::Target:
344*f4a2713aSLionel Sambuc     cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(getAssembler());
345*f4a2713aSLionel Sambuc     break;
346*f4a2713aSLionel Sambuc   case MCExpr::Constant:
347*f4a2713aSLionel Sambuc     break;
348*f4a2713aSLionel Sambuc 
349*f4a2713aSLionel Sambuc   case MCExpr::Binary: {
350*f4a2713aSLionel Sambuc     const MCBinaryExpr *be = cast<MCBinaryExpr>(expr);
351*f4a2713aSLionel Sambuc     fixSymbolsInTLSFixups(be->getLHS());
352*f4a2713aSLionel Sambuc     fixSymbolsInTLSFixups(be->getRHS());
353*f4a2713aSLionel Sambuc     break;
354*f4a2713aSLionel Sambuc   }
355*f4a2713aSLionel Sambuc 
356*f4a2713aSLionel Sambuc   case MCExpr::SymbolRef: {
357*f4a2713aSLionel Sambuc     const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr);
358*f4a2713aSLionel Sambuc     switch (symRef.getKind()) {
359*f4a2713aSLionel Sambuc     default:
360*f4a2713aSLionel Sambuc       return;
361*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_GOTTPOFF:
362*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_INDNTPOFF:
363*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_NTPOFF:
364*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_GOTNTPOFF:
365*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_TLSGD:
366*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_TLSLD:
367*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_TLSLDM:
368*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_TPOFF:
369*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_DTPOFF:
370*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_ARM_TLSGD:
371*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_ARM_TPOFF:
372*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_ARM_GOTTPOFF:
373*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_Mips_TLSGD:
374*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_Mips_GOTTPREL:
375*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_Mips_TPREL_HI:
376*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_Mips_TPREL_LO:
377*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_DTPMOD:
378*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_TPREL:
379*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_TPREL_LO:
380*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_TPREL_HI:
381*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_TPREL_HA:
382*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_TPREL_HIGHER:
383*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA:
384*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST:
385*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA:
386*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_DTPREL:
387*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_DTPREL_LO:
388*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_DTPREL_HI:
389*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_DTPREL_HA:
390*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER:
391*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA:
392*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST:
393*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA:
394*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_TPREL:
395*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO:
396*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI:
397*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA:
398*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_DTPREL:
399*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO:
400*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI:
401*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA:
402*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_TLS:
403*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_TLSGD:
404*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO:
405*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI:
406*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA:
407*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_TLSGD:
408*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_TLSLD:
409*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO:
410*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI:
411*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA:
412*f4a2713aSLionel Sambuc     case MCSymbolRefExpr::VK_PPC_TLSLD:
413*f4a2713aSLionel Sambuc       break;
414*f4a2713aSLionel Sambuc     }
415*f4a2713aSLionel Sambuc     MCSymbolData &SD = getAssembler().getOrCreateSymbolData(symRef.getSymbol());
416*f4a2713aSLionel Sambuc     MCELF::SetType(SD, ELF::STT_TLS);
417*f4a2713aSLionel Sambuc     break;
418*f4a2713aSLionel Sambuc   }
419*f4a2713aSLionel Sambuc 
420*f4a2713aSLionel Sambuc   case MCExpr::Unary:
421*f4a2713aSLionel Sambuc     fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
422*f4a2713aSLionel Sambuc     break;
423*f4a2713aSLionel Sambuc   }
424*f4a2713aSLionel Sambuc }
425*f4a2713aSLionel Sambuc 
426*f4a2713aSLionel Sambuc void MCELFStreamer::EmitInstToFragment(const MCInst &Inst) {
427*f4a2713aSLionel Sambuc   this->MCObjectStreamer::EmitInstToFragment(Inst);
428*f4a2713aSLionel Sambuc   MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment());
429*f4a2713aSLionel Sambuc 
430*f4a2713aSLionel Sambuc   for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
431*f4a2713aSLionel Sambuc     fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
432*f4a2713aSLionel Sambuc }
433*f4a2713aSLionel Sambuc 
434*f4a2713aSLionel Sambuc void MCELFStreamer::EmitInstToData(const MCInst &Inst) {
435*f4a2713aSLionel Sambuc   MCAssembler &Assembler = getAssembler();
436*f4a2713aSLionel Sambuc   SmallVector<MCFixup, 4> Fixups;
437*f4a2713aSLionel Sambuc   SmallString<256> Code;
438*f4a2713aSLionel Sambuc   raw_svector_ostream VecOS(Code);
439*f4a2713aSLionel Sambuc   Assembler.getEmitter().EncodeInstruction(Inst, VecOS, Fixups);
440*f4a2713aSLionel Sambuc   VecOS.flush();
441*f4a2713aSLionel Sambuc 
442*f4a2713aSLionel Sambuc   for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
443*f4a2713aSLionel Sambuc     fixSymbolsInTLSFixups(Fixups[i].getValue());
444*f4a2713aSLionel Sambuc 
445*f4a2713aSLionel Sambuc   // There are several possibilities here:
446*f4a2713aSLionel Sambuc   //
447*f4a2713aSLionel Sambuc   // If bundling is disabled, append the encoded instruction to the current data
448*f4a2713aSLionel Sambuc   // fragment (or create a new such fragment if the current fragment is not a
449*f4a2713aSLionel Sambuc   // data fragment).
450*f4a2713aSLionel Sambuc   //
451*f4a2713aSLionel Sambuc   // If bundling is enabled:
452*f4a2713aSLionel Sambuc   // - If we're not in a bundle-locked group, emit the instruction into a
453*f4a2713aSLionel Sambuc   //   fragment of its own. If there are no fixups registered for the
454*f4a2713aSLionel Sambuc   //   instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a
455*f4a2713aSLionel Sambuc   //   MCDataFragment.
456*f4a2713aSLionel Sambuc   // - If we're in a bundle-locked group, append the instruction to the current
457*f4a2713aSLionel Sambuc   //   data fragment because we want all the instructions in a group to get into
458*f4a2713aSLionel Sambuc   //   the same fragment. Be careful not to do that for the first instruction in
459*f4a2713aSLionel Sambuc   //   the group, though.
460*f4a2713aSLionel Sambuc   MCDataFragment *DF;
461*f4a2713aSLionel Sambuc 
462*f4a2713aSLionel Sambuc   if (Assembler.isBundlingEnabled()) {
463*f4a2713aSLionel Sambuc     MCSectionData *SD = getCurrentSectionData();
464*f4a2713aSLionel Sambuc     if (SD->isBundleLocked() && !SD->isBundleGroupBeforeFirstInst())
465*f4a2713aSLionel Sambuc       // If we are bundle-locked, we re-use the current fragment.
466*f4a2713aSLionel Sambuc       // The bundle-locking directive ensures this is a new data fragment.
467*f4a2713aSLionel Sambuc       DF = cast<MCDataFragment>(getCurrentFragment());
468*f4a2713aSLionel Sambuc     else if (!SD->isBundleLocked() && Fixups.size() == 0) {
469*f4a2713aSLionel Sambuc       // Optimize memory usage by emitting the instruction to a
470*f4a2713aSLionel Sambuc       // MCCompactEncodedInstFragment when not in a bundle-locked group and
471*f4a2713aSLionel Sambuc       // there are no fixups registered.
472*f4a2713aSLionel Sambuc       MCCompactEncodedInstFragment *CEIF = new MCCompactEncodedInstFragment();
473*f4a2713aSLionel Sambuc       insert(CEIF);
474*f4a2713aSLionel Sambuc       CEIF->getContents().append(Code.begin(), Code.end());
475*f4a2713aSLionel Sambuc       return;
476*f4a2713aSLionel Sambuc     } else {
477*f4a2713aSLionel Sambuc       DF = new MCDataFragment();
478*f4a2713aSLionel Sambuc       insert(DF);
479*f4a2713aSLionel Sambuc       if (SD->getBundleLockState() == MCSectionData::BundleLockedAlignToEnd) {
480*f4a2713aSLionel Sambuc         // If this is a new fragment created for a bundle-locked group, and the
481*f4a2713aSLionel Sambuc         // group was marked as "align_to_end", set a flag in the fragment.
482*f4a2713aSLionel Sambuc         DF->setAlignToBundleEnd(true);
483*f4a2713aSLionel Sambuc       }
484*f4a2713aSLionel Sambuc     }
485*f4a2713aSLionel Sambuc 
486*f4a2713aSLionel Sambuc     // We're now emitting an instruction in a bundle group, so this flag has
487*f4a2713aSLionel Sambuc     // to be turned off.
488*f4a2713aSLionel Sambuc     SD->setBundleGroupBeforeFirstInst(false);
489*f4a2713aSLionel Sambuc   } else {
490*f4a2713aSLionel Sambuc     DF = getOrCreateDataFragment();
491*f4a2713aSLionel Sambuc   }
492*f4a2713aSLionel Sambuc 
493*f4a2713aSLionel Sambuc   // Add the fixups and data.
494*f4a2713aSLionel Sambuc   for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
495*f4a2713aSLionel Sambuc     Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
496*f4a2713aSLionel Sambuc     DF->getFixups().push_back(Fixups[i]);
497*f4a2713aSLionel Sambuc   }
498*f4a2713aSLionel Sambuc   DF->setHasInstructions(true);
499*f4a2713aSLionel Sambuc   DF->getContents().append(Code.begin(), Code.end());
500*f4a2713aSLionel Sambuc }
501*f4a2713aSLionel Sambuc 
502*f4a2713aSLionel Sambuc void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
503*f4a2713aSLionel Sambuc   assert(AlignPow2 <= 30 && "Invalid bundle alignment");
504*f4a2713aSLionel Sambuc   MCAssembler &Assembler = getAssembler();
505*f4a2713aSLionel Sambuc   if (Assembler.getBundleAlignSize() == 0 && AlignPow2 > 0)
506*f4a2713aSLionel Sambuc     Assembler.setBundleAlignSize(1 << AlignPow2);
507*f4a2713aSLionel Sambuc   else
508*f4a2713aSLionel Sambuc     report_fatal_error(".bundle_align_mode should be only set once per file");
509*f4a2713aSLionel Sambuc }
510*f4a2713aSLionel Sambuc 
511*f4a2713aSLionel Sambuc void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
512*f4a2713aSLionel Sambuc   MCSectionData *SD = getCurrentSectionData();
513*f4a2713aSLionel Sambuc 
514*f4a2713aSLionel Sambuc   // Sanity checks
515*f4a2713aSLionel Sambuc   //
516*f4a2713aSLionel Sambuc   if (!getAssembler().isBundlingEnabled())
517*f4a2713aSLionel Sambuc     report_fatal_error(".bundle_lock forbidden when bundling is disabled");
518*f4a2713aSLionel Sambuc   else if (SD->isBundleLocked())
519*f4a2713aSLionel Sambuc     report_fatal_error("Nesting of .bundle_lock is forbidden");
520*f4a2713aSLionel Sambuc 
521*f4a2713aSLionel Sambuc   SD->setBundleLockState(AlignToEnd ? MCSectionData::BundleLockedAlignToEnd :
522*f4a2713aSLionel Sambuc                                       MCSectionData::BundleLocked);
523*f4a2713aSLionel Sambuc   SD->setBundleGroupBeforeFirstInst(true);
524*f4a2713aSLionel Sambuc }
525*f4a2713aSLionel Sambuc 
526*f4a2713aSLionel Sambuc void MCELFStreamer::EmitBundleUnlock() {
527*f4a2713aSLionel Sambuc   MCSectionData *SD = getCurrentSectionData();
528*f4a2713aSLionel Sambuc 
529*f4a2713aSLionel Sambuc   // Sanity checks
530*f4a2713aSLionel Sambuc   if (!getAssembler().isBundlingEnabled())
531*f4a2713aSLionel Sambuc     report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
532*f4a2713aSLionel Sambuc   else if (!SD->isBundleLocked())
533*f4a2713aSLionel Sambuc     report_fatal_error(".bundle_unlock without matching lock");
534*f4a2713aSLionel Sambuc   else if (SD->isBundleGroupBeforeFirstInst())
535*f4a2713aSLionel Sambuc     report_fatal_error("Empty bundle-locked group is forbidden");
536*f4a2713aSLionel Sambuc 
537*f4a2713aSLionel Sambuc   SD->setBundleLockState(MCSectionData::NotBundleLocked);
538*f4a2713aSLionel Sambuc }
539*f4a2713aSLionel Sambuc 
540*f4a2713aSLionel Sambuc void MCELFStreamer::Flush() {
541*f4a2713aSLionel Sambuc   for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),
542*f4a2713aSLionel Sambuc                                                 e = LocalCommons.end();
543*f4a2713aSLionel Sambuc        i != e; ++i) {
544*f4a2713aSLionel Sambuc     MCSymbolData *SD = i->SD;
545*f4a2713aSLionel Sambuc     uint64_t Size = i->Size;
546*f4a2713aSLionel Sambuc     unsigned ByteAlignment = i->ByteAlignment;
547*f4a2713aSLionel Sambuc     const MCSymbol &Symbol = SD->getSymbol();
548*f4a2713aSLionel Sambuc     const MCSection &Section = Symbol.getSection();
549*f4a2713aSLionel Sambuc 
550*f4a2713aSLionel Sambuc     MCSectionData &SectData = getAssembler().getOrCreateSectionData(Section);
551*f4a2713aSLionel Sambuc     new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &SectData);
552*f4a2713aSLionel Sambuc 
553*f4a2713aSLionel Sambuc     MCFragment *F = new MCFillFragment(0, 0, Size, &SectData);
554*f4a2713aSLionel Sambuc     SD->setFragment(F);
555*f4a2713aSLionel Sambuc 
556*f4a2713aSLionel Sambuc     // Update the maximum alignment of the section if necessary.
557*f4a2713aSLionel Sambuc     if (ByteAlignment > SectData.getAlignment())
558*f4a2713aSLionel Sambuc       SectData.setAlignment(ByteAlignment);
559*f4a2713aSLionel Sambuc   }
560*f4a2713aSLionel Sambuc 
561*f4a2713aSLionel Sambuc   LocalCommons.clear();
562*f4a2713aSLionel Sambuc }
563*f4a2713aSLionel Sambuc 
564*f4a2713aSLionel Sambuc void MCELFStreamer::FinishImpl() {
565*f4a2713aSLionel Sambuc   EmitFrames(NULL, true);
566*f4a2713aSLionel Sambuc 
567*f4a2713aSLionel Sambuc   Flush();
568*f4a2713aSLionel Sambuc 
569*f4a2713aSLionel Sambuc   this->MCObjectStreamer::FinishImpl();
570*f4a2713aSLionel Sambuc }
571*f4a2713aSLionel Sambuc 
572*f4a2713aSLionel Sambuc MCStreamer *llvm::createELFStreamer(MCContext &Context,
573*f4a2713aSLionel Sambuc                                     MCTargetStreamer *Streamer,
574*f4a2713aSLionel Sambuc                                     MCAsmBackend &MAB, raw_ostream &OS,
575*f4a2713aSLionel Sambuc                                     MCCodeEmitter *CE, bool RelaxAll,
576*f4a2713aSLionel Sambuc                                     bool NoExecStack) {
577*f4a2713aSLionel Sambuc   MCELFStreamer *S = new MCELFStreamer(Context, Streamer, MAB, OS, CE);
578*f4a2713aSLionel Sambuc   if (RelaxAll)
579*f4a2713aSLionel Sambuc     S->getAssembler().setRelaxAll(true);
580*f4a2713aSLionel Sambuc   if (NoExecStack)
581*f4a2713aSLionel Sambuc     S->getAssembler().setNoExecStack(true);
582*f4a2713aSLionel Sambuc   return S;
583*f4a2713aSLionel Sambuc }
584*f4a2713aSLionel Sambuc 
585*f4a2713aSLionel Sambuc void MCELFStreamer::EmitThumbFunc(MCSymbol *Func) {
586*f4a2713aSLionel Sambuc   llvm_unreachable("Generic ELF doesn't support this directive");
587*f4a2713aSLionel Sambuc }
588*f4a2713aSLionel Sambuc 
589*f4a2713aSLionel Sambuc MCSymbolData &MCELFStreamer::getOrCreateSymbolData(MCSymbol *Symbol) {
590*f4a2713aSLionel Sambuc   return getAssembler().getOrCreateSymbolData(*Symbol);
591*f4a2713aSLionel Sambuc }
592*f4a2713aSLionel Sambuc 
593*f4a2713aSLionel Sambuc void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
594*f4a2713aSLionel Sambuc   llvm_unreachable("ELF doesn't support this directive");
595*f4a2713aSLionel Sambuc }
596*f4a2713aSLionel Sambuc 
597*f4a2713aSLionel Sambuc void MCELFStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
598*f4a2713aSLionel Sambuc   llvm_unreachable("ELF doesn't support this directive");
599*f4a2713aSLionel Sambuc }
600*f4a2713aSLionel Sambuc 
601*f4a2713aSLionel Sambuc void MCELFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
602*f4a2713aSLionel Sambuc   llvm_unreachable("ELF doesn't support this directive");
603*f4a2713aSLionel Sambuc }
604*f4a2713aSLionel Sambuc 
605*f4a2713aSLionel Sambuc void MCELFStreamer::EmitCOFFSymbolType(int Type) {
606*f4a2713aSLionel Sambuc   llvm_unreachable("ELF doesn't support this directive");
607*f4a2713aSLionel Sambuc }
608*f4a2713aSLionel Sambuc 
609*f4a2713aSLionel Sambuc void MCELFStreamer::EndCOFFSymbolDef() {
610*f4a2713aSLionel Sambuc   llvm_unreachable("ELF doesn't support this directive");
611*f4a2713aSLionel Sambuc }
612*f4a2713aSLionel Sambuc 
613*f4a2713aSLionel Sambuc void MCELFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
614*f4a2713aSLionel Sambuc                                  uint64_t Size, unsigned ByteAlignment) {
615*f4a2713aSLionel Sambuc   llvm_unreachable("ELF doesn't support this directive");
616*f4a2713aSLionel Sambuc }
617*f4a2713aSLionel Sambuc 
618*f4a2713aSLionel Sambuc void MCELFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
619*f4a2713aSLionel Sambuc                                    uint64_t Size, unsigned ByteAlignment) {
620*f4a2713aSLionel Sambuc   llvm_unreachable("ELF doesn't support this directive");
621*f4a2713aSLionel Sambuc }
622