Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- MCELFStreamer.h - MCStreamer ELF Object File Interface ---*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_MC_MCELFSTREAMER_H |
| 10 | #define LLVM_MC_MCELFSTREAMER_H |
| 11 | |
| 12 | #include "llvm/ADT/SmallVector.h" |
| 13 | #include "llvm/MC/MCDirectives.h" |
| 14 | #include "llvm/MC/MCObjectStreamer.h" |
| 15 | |
| 16 | namespace llvm { |
| 17 | |
| 18 | class MCAsmBackend; |
| 19 | class MCCodeEmitter; |
| 20 | class MCExpr; |
| 21 | class MCInst; |
| 22 | |
| 23 | class MCELFStreamer : public MCObjectStreamer { |
| 24 | public: |
| 25 | MCELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB, |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 26 | std::unique_ptr<MCObjectWriter> OW, |
| 27 | std::unique_ptr<MCCodeEmitter> Emitter); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 28 | |
| 29 | ~MCELFStreamer() override = default; |
| 30 | |
| 31 | /// state management |
| 32 | void reset() override { |
| 33 | SeenIdent = false; |
| 34 | BundleGroups.clear(); |
| 35 | MCObjectStreamer::reset(); |
| 36 | } |
| 37 | |
| 38 | /// \name MCStreamer Interface |
| 39 | /// @{ |
| 40 | |
| 41 | void InitSections(bool NoExecStack) override; |
| 42 | void ChangeSection(MCSection *Section, const MCExpr *Subsection) override; |
| 43 | void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override; |
| 44 | void EmitLabel(MCSymbol *Symbol, SMLoc Loc, MCFragment *F) override; |
| 45 | void EmitAssemblerFlag(MCAssemblerFlag Flag) override; |
| 46 | void EmitThumbFunc(MCSymbol *Func) override; |
| 47 | void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override; |
| 48 | bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override; |
| 49 | void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override; |
| 50 | void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
| 51 | unsigned ByteAlignment) override; |
| 52 | |
| 53 | void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override; |
| 54 | void emitELFSymverDirective(StringRef AliasName, |
| 55 | const MCSymbol *Aliasee) override; |
| 56 | |
| 57 | void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, |
| 58 | unsigned ByteAlignment) override; |
| 59 | |
| 60 | void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 61 | uint64_t Size = 0, unsigned ByteAlignment = 0, |
| 62 | SMLoc L = SMLoc()) override; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 63 | void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, |
| 64 | unsigned ByteAlignment = 0) override; |
| 65 | void EmitValueImpl(const MCExpr *Value, unsigned Size, |
| 66 | SMLoc Loc = SMLoc()) override; |
| 67 | |
| 68 | void EmitIdent(StringRef IdentString) override; |
| 69 | |
| 70 | void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override; |
| 71 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 72 | void emitCGProfileEntry(const MCSymbolRefExpr *From, |
| 73 | const MCSymbolRefExpr *To, uint64_t Count) override; |
| 74 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 75 | void FinishImpl() override; |
| 76 | |
| 77 | void EmitBundleAlignMode(unsigned AlignPow2) override; |
| 78 | void EmitBundleLock(bool AlignToEnd) override; |
| 79 | void EmitBundleUnlock() override; |
| 80 | |
| 81 | private: |
| 82 | bool isBundleLocked() const; |
| 83 | void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override; |
| 84 | void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override; |
| 85 | |
| 86 | void fixSymbolsInTLSFixups(const MCExpr *expr); |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 87 | void finalizeCGProfileEntry(const MCSymbolRefExpr *&S); |
| 88 | void finalizeCGProfile(); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 89 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 90 | /// Merge the content of the fragment \p EF into the fragment \p DF. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 91 | void mergeFragment(MCDataFragment *, MCDataFragment *); |
| 92 | |
| 93 | bool SeenIdent = false; |
| 94 | |
| 95 | /// BundleGroups - The stack of fragments holding the bundle-locked |
| 96 | /// instructions. |
| 97 | SmallVector<MCDataFragment *, 4> BundleGroups; |
| 98 | }; |
| 99 | |
| 100 | MCELFStreamer *createARMELFStreamer(MCContext &Context, |
| 101 | std::unique_ptr<MCAsmBackend> TAB, |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 102 | std::unique_ptr<MCObjectWriter> OW, |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 103 | std::unique_ptr<MCCodeEmitter> Emitter, |
| 104 | bool RelaxAll, bool IsThumb); |
| 105 | |
| 106 | } // end namespace llvm |
| 107 | |
| 108 | #endif // LLVM_MC_MCELFSTREAMER_H |