MCELFStreamer.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //===- MCELFStreamer.h - MCStreamer ELF Object File Interface ---*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_MC_MCELFSTREAMER_H
  9. #define LLVM_MC_MCELFSTREAMER_H
  10. #include "llvm/ADT/SmallVector.h"
  11. #include "llvm/MC/MCDirectives.h"
  12. #include "llvm/MC/MCObjectStreamer.h"
  13. namespace llvm {
  14. class MCAsmBackend;
  15. class MCCodeEmitter;
  16. class MCExpr;
  17. class MCInst;
  18. class MCELFStreamer : public MCObjectStreamer {
  19. public:
  20. MCELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
  21. std::unique_ptr<MCObjectWriter> OW,
  22. std::unique_ptr<MCCodeEmitter> Emitter);
  23. ~MCELFStreamer() override = default;
  24. /// state management
  25. void reset() override {
  26. SeenIdent = false;
  27. BundleGroups.clear();
  28. MCObjectStreamer::reset();
  29. }
  30. /// \name MCStreamer Interface
  31. /// @{
  32. void InitSections(bool NoExecStack) override;
  33. void changeSection(MCSection *Section, const MCExpr *Subsection) override;
  34. void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
  35. void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment *F,
  36. uint64_t Offset) override;
  37. void emitAssemblerFlag(MCAssemblerFlag Flag) override;
  38. void emitThumbFunc(MCSymbol *Func) override;
  39. void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
  40. bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
  41. void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
  42. void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
  43. unsigned ByteAlignment) override;
  44. void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
  45. void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name,
  46. bool KeepOriginalSym) override;
  47. void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
  48. unsigned ByteAlignment) override;
  49. void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
  50. uint64_t Size = 0, unsigned ByteAlignment = 0,
  51. SMLoc L = SMLoc()) override;
  52. void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
  53. unsigned ByteAlignment = 0) override;
  54. void emitValueImpl(const MCExpr *Value, unsigned Size,
  55. SMLoc Loc = SMLoc()) override;
  56. void emitIdent(StringRef IdentString) override;
  57. void emitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override;
  58. void emitCGProfileEntry(const MCSymbolRefExpr *From,
  59. const MCSymbolRefExpr *To, uint64_t Count) override;
  60. void finishImpl() override;
  61. void emitBundleAlignMode(unsigned AlignPow2) override;
  62. void emitBundleLock(bool AlignToEnd) override;
  63. void emitBundleUnlock() override;
  64. private:
  65. bool isBundleLocked() const;
  66. void emitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override;
  67. void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
  68. void fixSymbolsInTLSFixups(const MCExpr *expr);
  69. void finalizeCGProfileEntry(const MCSymbolRefExpr *&S);
  70. void finalizeCGProfile();
  71. /// Merge the content of the fragment \p EF into the fragment \p DF.
  72. void mergeFragment(MCDataFragment *, MCDataFragment *);
  73. bool SeenIdent = false;
  74. /// BundleGroups - The stack of fragments holding the bundle-locked
  75. /// instructions.
  76. SmallVector<MCDataFragment *, 4> BundleGroups;
  77. };
  78. MCELFStreamer *createARMELFStreamer(MCContext &Context,
  79. std::unique_ptr<MCAsmBackend> TAB,
  80. std::unique_ptr<MCObjectWriter> OW,
  81. std::unique_ptr<MCCodeEmitter> Emitter,
  82. bool RelaxAll, bool IsThumb, bool IsAndroid);
  83. } // end namespace llvm
  84. #endif // LLVM_MC_MCELFSTREAMER_H