1 //===- lib/MC/MCELFStreamer.h - ELF Object Output -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file assembles .s files and emits ELF .o object files.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_MC_MCELFSTREAMER_H
15 #define LLVM_MC_MCELFSTREAMER_H
17 #include "llvm/ADT/SmallPtrSet.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/MC/MCAssembler.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCObjectStreamer.h"
22 #include "llvm/MC/MCSectionELF.h"
26 class MCELFStreamer
: public MCObjectStreamer
{
28 MCELFStreamer(MCContext
&Context
, TargetAsmBackend
&TAB
,
29 raw_ostream
&OS
, MCCodeEmitter
*Emitter
)
30 : MCObjectStreamer(Context
, TAB
, OS
, Emitter
) {}
32 MCELFStreamer(MCContext
&Context
, TargetAsmBackend
&TAB
,
33 raw_ostream
&OS
, MCCodeEmitter
*Emitter
,
34 MCAssembler
*Assembler
)
35 : MCObjectStreamer(Context
, TAB
, OS
, Emitter
, Assembler
) {}
40 /// @name MCStreamer Interface
43 virtual void InitSections();
44 virtual void ChangeSection(const MCSection
*Section
);
45 virtual void EmitLabel(MCSymbol
*Symbol
);
46 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag
);
47 virtual void EmitThumbFunc(MCSymbol
*Func
);
48 virtual void EmitAssignment(MCSymbol
*Symbol
, const MCExpr
*Value
);
49 virtual void EmitWeakReference(MCSymbol
*Alias
, const MCSymbol
*Symbol
);
50 virtual void EmitSymbolAttribute(MCSymbol
*Symbol
, MCSymbolAttr Attribute
);
51 virtual void EmitSymbolDesc(MCSymbol
*Symbol
, unsigned DescValue
) {
52 assert(0 && "ELF doesn't support this directive");
54 virtual void EmitCommonSymbol(MCSymbol
*Symbol
, uint64_t Size
,
55 unsigned ByteAlignment
);
56 virtual void BeginCOFFSymbolDef(const MCSymbol
*Symbol
) {
57 assert(0 && "ELF doesn't support this directive");
60 virtual void EmitCOFFSymbolStorageClass(int StorageClass
) {
61 assert(0 && "ELF doesn't support this directive");
64 virtual void EmitCOFFSymbolType(int Type
) {
65 assert(0 && "ELF doesn't support this directive");
68 virtual void EndCOFFSymbolDef() {
69 assert(0 && "ELF doesn't support this directive");
72 virtual void EmitELFSize(MCSymbol
*Symbol
, const MCExpr
*Value
) {
73 MCSymbolData
&SD
= getAssembler().getOrCreateSymbolData(*Symbol
);
77 virtual void EmitLocalCommonSymbol(MCSymbol
*Symbol
, uint64_t Size
);
79 virtual void EmitZerofill(const MCSection
*Section
, MCSymbol
*Symbol
= 0,
80 unsigned Size
= 0, unsigned ByteAlignment
= 0) {
81 assert(0 && "ELF doesn't support this directive");
83 virtual void EmitTBSSSymbol(const MCSection
*Section
, MCSymbol
*Symbol
,
84 uint64_t Size
, unsigned ByteAlignment
= 0) {
85 assert(0 && "ELF doesn't support this directive");
87 virtual void EmitBytes(StringRef Data
, unsigned AddrSpace
);
88 virtual void EmitValueToAlignment(unsigned ByteAlignment
, int64_t Value
= 0,
89 unsigned ValueSize
= 1,
90 unsigned MaxBytesToEmit
= 0);
91 virtual void EmitCodeAlignment(unsigned ByteAlignment
,
92 unsigned MaxBytesToEmit
= 0);
94 virtual void EmitFileDirective(StringRef Filename
);
96 virtual void Finish();
99 virtual void EmitInstToFragment(const MCInst
&Inst
);
100 virtual void EmitInstToData(const MCInst
&Inst
);
102 void fixSymbolsInTLSFixups(const MCExpr
*expr
);
107 unsigned ByteAlignment
;
109 std::vector
<LocalCommon
> LocalCommons
;
111 SmallPtrSet
<MCSymbol
*, 16> BindingExplicitlySet
;
113 void SetSection(StringRef Section
, unsigned Type
, unsigned Flags
,
115 SwitchSection(getContext().getELFSection(Section
, Type
, Flags
, Kind
));
118 void SetSectionData() {
119 SetSection(".data", ELF::SHT_PROGBITS
,
120 ELF::SHF_WRITE
|ELF::SHF_ALLOC
,
121 SectionKind::getDataRel());
122 EmitCodeAlignment(4, 0);
124 void SetSectionText() {
125 SetSection(".text", ELF::SHT_PROGBITS
,
127 ELF::SHF_ALLOC
, SectionKind::getText());
128 EmitCodeAlignment(4, 0);
130 void SetSectionBss() {
131 SetSection(".bss", ELF::SHT_NOBITS
,
133 ELF::SHF_ALLOC
, SectionKind::getBSS());
134 EmitCodeAlignment(4, 0);
138 } // end llvm namespace
141 //===- lib/MC/MCELFStreamer.h - ELF Object Output -------------------------===//
143 // The LLVM Compiler Infrastructure
145 // This file is distributed under the University of Illinois Open Source
146 // License. See LICENSE.TXT for details.
148 //===----------------------------------------------------------------------===//
150 // This file assembles .s files and emits ELF .o object files.
152 //===----------------------------------------------------------------------===//
154 #ifndef LLVM_MC_MCELFSTREAMER_H
155 #define LLVM_MC_MCELFSTREAMER_H
157 #include "llvm/ADT/SmallPtrSet.h"
158 #include "llvm/ADT/DenseMap.h"
159 #include "llvm/MC/MCAssembler.h"
160 #include "llvm/MC/MCContext.h"
161 #include "llvm/MC/MCObjectStreamer.h"
162 #include "llvm/MC/MCSectionELF.h"
166 class MCELFStreamer
: public MCObjectStreamer
{
168 MCELFStreamer(MCContext
&Context
, TargetAsmBackend
&TAB
,
169 raw_ostream
&OS
, MCCodeEmitter
*Emitter
)
170 : MCObjectStreamer(Context
, TAB
, OS
, Emitter
) {}
174 /// @name MCStreamer Interface
177 virtual void InitSections();
178 virtual void ChangeSection(const MCSection
*Section
);
179 virtual void EmitLabel(MCSymbol
*Symbol
);
180 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag
);
181 virtual void EmitThumbFunc(MCSymbol
*Func
);
182 virtual void EmitAssignment(MCSymbol
*Symbol
, const MCExpr
*Value
);
183 virtual void EmitWeakReference(MCSymbol
*Alias
, const MCSymbol
*Symbol
);
184 virtual void EmitSymbolAttribute(MCSymbol
*Symbol
, MCSymbolAttr Attribute
);
185 virtual void EmitSymbolDesc(MCSymbol
*Symbol
, unsigned DescValue
) {
186 assert(0 && "ELF doesn't support this directive");
188 virtual void EmitCommonSymbol(MCSymbol
*Symbol
, uint64_t Size
,
189 unsigned ByteAlignment
);
190 virtual void BeginCOFFSymbolDef(const MCSymbol
*Symbol
) {
191 assert(0 && "ELF doesn't support this directive");
194 virtual void EmitCOFFSymbolStorageClass(int StorageClass
) {
195 assert(0 && "ELF doesn't support this directive");
198 virtual void EmitCOFFSymbolType(int Type
) {
199 assert(0 && "ELF doesn't support this directive");
202 virtual void EndCOFFSymbolDef() {
203 assert(0 && "ELF doesn't support this directive");
206 virtual void EmitELFSize(MCSymbol
*Symbol
, const MCExpr
*Value
) {
207 MCSymbolData
&SD
= getAssembler().getOrCreateSymbolData(*Symbol
);
211 virtual void EmitLocalCommonSymbol(MCSymbol
*Symbol
, uint64_t Size
);
213 virtual void EmitZerofill(const MCSection
*Section
, MCSymbol
*Symbol
= 0,
214 unsigned Size
= 0, unsigned ByteAlignment
= 0) {
215 assert(0 && "ELF doesn't support this directive");
217 virtual void EmitTBSSSymbol(const MCSection
*Section
, MCSymbol
*Symbol
,
218 uint64_t Size
, unsigned ByteAlignment
= 0) {
219 assert(0 && "ELF doesn't support this directive");
221 virtual void EmitBytes(StringRef Data
, unsigned AddrSpace
);
222 virtual void EmitValueToAlignment(unsigned ByteAlignment
, int64_t Value
= 0,
223 unsigned ValueSize
= 1,
224 unsigned MaxBytesToEmit
= 0);
225 virtual void EmitCodeAlignment(unsigned ByteAlignment
,
226 unsigned MaxBytesToEmit
= 0);
228 virtual void EmitFileDirective(StringRef Filename
);
230 virtual void Finish();
233 virtual void EmitInstToFragment(const MCInst
&Inst
);
234 virtual void EmitInstToData(const MCInst
&Inst
);
236 void fixSymbolsInTLSFixups(const MCExpr
*expr
);
241 unsigned ByteAlignment
;
243 std::vector
<LocalCommon
> LocalCommons
;
245 SmallPtrSet
<MCSymbol
*, 16> BindingExplicitlySet
;
247 void SetSection(StringRef Section
, unsigned Type
, unsigned Flags
,
249 SwitchSection(getContext().getELFSection(Section
, Type
, Flags
, Kind
));
252 void SetSectionData() {
253 SetSection(".data", ELF::SHT_PROGBITS
,
254 ELF::SHF_WRITE
|ELF::SHF_ALLOC
,
255 SectionKind::getDataRel());
256 EmitCodeAlignment(4, 0);
258 void SetSectionText() {
259 SetSection(".text", ELF::SHT_PROGBITS
,
261 ELF::SHF_ALLOC
, SectionKind::getText());
262 EmitCodeAlignment(4, 0);
264 void SetSectionBss() {
265 SetSection(".bss", ELF::SHT_NOBITS
,
267 ELF::SHF_ALLOC
, SectionKind::getBSS());
268 EmitCodeAlignment(4, 0);
272 } // end llvm namespace