1 //===- MCELFStreamer.h - MCStreamer ELF Object File Interface ---*- 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 #ifndef LLVM_MC_MCELFSTREAMER_H 11 #define LLVM_MC_MCELFSTREAMER_H 12 13 #include "llvm/ADT/SmallPtrSet.h" 14 #include "llvm/MC/MCDirectives.h" 15 #include "llvm/MC/MCObjectStreamer.h" 16 #include "llvm/MC/SectionKind.h" 17 #include "llvm/Support/DataTypes.h" 18 #include <vector> 19 20 namespace llvm { 21 class MCAsmBackend; 22 class MCAssembler; 23 class MCCodeEmitter; 24 class MCExpr; 25 class MCInst; 26 class MCSymbol; 27 class MCSymbolData; 28 class raw_ostream; 29 30 class MCELFStreamer : public MCObjectStreamer { 31 protected: MCELFStreamer(StreamerKind Kind,MCContext & Context,MCAsmBackend & TAB,raw_ostream & OS,MCCodeEmitter * Emitter)32 MCELFStreamer(StreamerKind Kind, MCContext &Context, MCAsmBackend &TAB, 33 raw_ostream &OS, MCCodeEmitter *Emitter) 34 : MCObjectStreamer(Kind, Context, TAB, OS, Emitter) {} 35 36 public: MCELFStreamer(MCContext & Context,MCAsmBackend & TAB,raw_ostream & OS,MCCodeEmitter * Emitter)37 MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS, 38 MCCodeEmitter *Emitter) 39 : MCObjectStreamer(SK_ELFStreamer, Context, TAB, OS, Emitter) {} 40 MCELFStreamer(MCContext & Context,MCAsmBackend & TAB,raw_ostream & OS,MCCodeEmitter * Emitter,MCAssembler * Assembler)41 MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS, 42 MCCodeEmitter *Emitter, MCAssembler *Assembler) 43 : MCObjectStreamer(SK_ELFStreamer, Context, TAB, OS, Emitter, 44 Assembler) {} 45 46 virtual ~MCELFStreamer(); 47 48 /// @name MCStreamer Interface 49 /// @{ 50 51 virtual void InitSections(); 52 virtual void InitToTextSection(); 53 virtual void ChangeSection(const MCSection *Section); 54 virtual void EmitLabel(MCSymbol *Symbol); 55 virtual void EmitDebugLabel(MCSymbol *Symbol); 56 virtual void EmitAssemblerFlag(MCAssemblerFlag Flag); 57 virtual void EmitThumbFunc(MCSymbol *Func); 58 virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol); 59 virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute); 60 virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue); 61 virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, 62 unsigned ByteAlignment); 63 virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol); 64 virtual void EmitCOFFSymbolStorageClass(int StorageClass); 65 virtual void EmitCOFFSymbolType(int Type); 66 virtual void EndCOFFSymbolDef(); 67 68 virtual MCSymbolData &getOrCreateSymbolData(MCSymbol *Symbol); 69 70 virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value); 71 72 virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, 73 unsigned ByteAlignment); 74 75 virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = 0, 76 uint64_t Size = 0, unsigned ByteAlignment = 0); 77 virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, 78 uint64_t Size, unsigned ByteAlignment = 0); 79 virtual void EmitValueImpl(const MCExpr *Value, unsigned Size, 80 unsigned AddrSpace); 81 82 virtual void EmitFileDirective(StringRef Filename); 83 84 virtual void EmitTCEntry(const MCSymbol &S); 85 86 virtual void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned); 87 88 virtual void FinishImpl(); 89 /// @} 90 classof(const MCStreamer * S)91 static bool classof(const MCStreamer *S) { 92 return S->getKind() == SK_ELFStreamer || S->getKind() == SK_ARMELFStreamer; 93 } 94 95 private: 96 virtual void EmitInstToFragment(const MCInst &Inst); 97 virtual void EmitInstToData(const MCInst &Inst); 98 99 virtual void EmitBundleAlignMode(unsigned AlignPow2); 100 virtual void EmitBundleLock(bool AlignToEnd); 101 virtual void EmitBundleUnlock(); 102 103 void fixSymbolsInTLSFixups(const MCExpr *expr); 104 105 struct LocalCommon { 106 MCSymbolData *SD; 107 uint64_t Size; 108 unsigned ByteAlignment; 109 }; 110 111 std::vector<LocalCommon> LocalCommons; 112 113 SmallPtrSet<MCSymbol *, 16> BindingExplicitlySet; 114 115 116 void SetSection(StringRef Section, unsigned Type, unsigned Flags, 117 SectionKind Kind); 118 void SetSectionData(); 119 void SetSectionText(); 120 void SetSectionBss(); 121 }; 122 123 } // end namespace llvm 124 125 #endif 126