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, MCAsmBackend &TAB,
29 raw_ostream &OS, MCCodeEmitter *Emitter)
30 : MCObjectStreamer(Context, TAB, OS, Emitter) {}
32 MCELFStreamer(MCContext &Context, MCAsmBackend &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,
78 unsigned ByteAlignment);
80 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0,
81 unsigned Size = 0, unsigned ByteAlignment = 0) {
82 assert(0 && "ELF doesn't support this directive");
84 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
85 uint64_t Size, unsigned ByteAlignment = 0) {
86 assert(0 && "ELF doesn't support this directive");
88 virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
89 virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
90 unsigned ValueSize = 1,
91 unsigned MaxBytesToEmit = 0);
92 virtual void EmitCodeAlignment(unsigned ByteAlignment,
93 unsigned MaxBytesToEmit = 0);
95 virtual void EmitFileDirective(StringRef Filename);
97 virtual void Finish();
100 virtual void EmitInstToFragment(const MCInst &Inst);
101 virtual void EmitInstToData(const MCInst &Inst);
103 void fixSymbolsInTLSFixups(const MCExpr *expr);
108 unsigned ByteAlignment;
110 std::vector<LocalCommon> LocalCommons;
112 SmallPtrSet<MCSymbol *, 16> BindingExplicitlySet;
114 void SetSection(StringRef Section, unsigned Type, unsigned Flags,
116 SwitchSection(getContext().getELFSection(Section, Type, Flags, Kind));
119 void SetSectionData() {
120 SetSection(".data", ELF::SHT_PROGBITS,
121 ELF::SHF_WRITE |ELF::SHF_ALLOC,
122 SectionKind::getDataRel());
123 EmitCodeAlignment(4, 0);
125 void SetSectionText() {
126 SetSection(".text", ELF::SHT_PROGBITS,
128 ELF::SHF_ALLOC, SectionKind::getText());
129 EmitCodeAlignment(4, 0);
131 void SetSectionBss() {
132 SetSection(".bss", ELF::SHT_NOBITS,
134 ELF::SHF_ALLOC, SectionKind::getBSS());
135 EmitCodeAlignment(4, 0);
139 } // end llvm namespace