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 public: 32 MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS, 33 MCCodeEmitter *Emitter) 34 : MCObjectStreamer(Context, TAB, OS, Emitter), 35 SeenIdent(false) {} 36 37 MCELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS, 38 MCCodeEmitter *Emitter, MCAssembler *Assembler) 39 : MCObjectStreamer(Context, TAB, OS, Emitter, Assembler), 40 SeenIdent(false) {} 41 42 virtual ~MCELFStreamer(); 43 44 /// @name MCStreamer Interface 45 /// @{ 46 47 void InitSections() override; 48 void ChangeSection(const MCSection *Section, 49 const MCExpr *Subsection) override; 50 void EmitLabel(MCSymbol *Symbol) override; 51 void EmitAssemblerFlag(MCAssemblerFlag Flag) override; 52 void EmitThumbFunc(MCSymbol *Func) override; 53 void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override; 54 bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override; 55 void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override; 56 void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, 57 unsigned ByteAlignment) override; 58 void BeginCOFFSymbolDef(const MCSymbol *Symbol) override; 59 void EmitCOFFSymbolStorageClass(int StorageClass) override; 60 void EmitCOFFSymbolType(int Type) override; 61 void EndCOFFSymbolDef() override; 62 63 void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) override; 64 65 void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, 66 unsigned ByteAlignment) override; 67 68 void EmitZerofill(const MCSection *Section, MCSymbol *Symbol = nullptr, 69 uint64_t Size = 0, unsigned ByteAlignment = 0) override; 70 void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol, 71 uint64_t Size, unsigned ByteAlignment = 0) override; 72 void EmitValueImpl(const MCExpr *Value, unsigned Size, 73 const SMLoc &Loc = SMLoc()) override; 74 75 void EmitFileDirective(StringRef Filename) override; 76 77 void EmitIdent(StringRef IdentString) override; 78 79 void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override; 80 81 void Flush() override; 82 83 void FinishImpl() override; 84 85 void EmitBundleAlignMode(unsigned AlignPow2) override; 86 void EmitBundleLock(bool AlignToEnd) override; 87 void EmitBundleUnlock() override; 88 89 private: 90 void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override; 91 void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override; 92 93 void fixSymbolsInTLSFixups(const MCExpr *expr); 94 95 bool SeenIdent; 96 97 struct LocalCommon { 98 MCSymbolData *SD; 99 uint64_t Size; 100 unsigned ByteAlignment; 101 }; 102 103 std::vector<LocalCommon> LocalCommons; 104 105 SmallPtrSet<MCSymbol *, 16> BindingExplicitlySet; 106 }; 107 108 MCELFStreamer *createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, 109 raw_ostream &OS, MCCodeEmitter *Emitter, 110 bool RelaxAll, bool NoExecStack, 111 bool IsThumb); 112 113 } // end namespace llvm 114 115 #endif 116