File indexing completed on 2026-05-10 08:44:13
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_MC_MCELFSTREAMER_H
0010 #define LLVM_MC_MCELFSTREAMER_H
0011
0012 #include "llvm/ADT/SmallVector.h"
0013 #include "llvm/MC/MCDirectives.h"
0014 #include "llvm/MC/MCObjectStreamer.h"
0015
0016 namespace llvm {
0017
0018 class ELFObjectWriter;
0019 class MCContext;
0020 class MCDataFragment;
0021 class MCFragment;
0022 class MCObjectWriter;
0023 class MCSection;
0024 class MCSubtargetInfo;
0025 class MCSymbol;
0026 class MCSymbolRefExpr;
0027 class MCAsmBackend;
0028 class MCCodeEmitter;
0029 class MCExpr;
0030 class MCInst;
0031
0032 class MCELFStreamer : public MCObjectStreamer {
0033 public:
0034 MCELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
0035 std::unique_ptr<MCObjectWriter> OW,
0036 std::unique_ptr<MCCodeEmitter> Emitter);
0037
0038 ~MCELFStreamer() override = default;
0039
0040
0041 void reset() override {
0042 SeenIdent = false;
0043 MCObjectStreamer::reset();
0044 }
0045
0046 ELFObjectWriter &getWriter();
0047
0048
0049
0050
0051 void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override;
0052 void changeSection(MCSection *Section, uint32_t Subsection = 0) override;
0053 void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
0054 void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F,
0055 uint64_t Offset) override;
0056 void emitAssemblerFlag(MCAssemblerFlag Flag) override;
0057 void emitThumbFunc(MCSymbol *Func) override;
0058 void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
0059 bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
0060 void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
0061 void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
0062 Align ByteAlignment) override;
0063
0064 void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
0065 void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name,
0066 bool KeepOriginalSym) override;
0067
0068 void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
0069 Align ByteAlignment) override;
0070
0071 void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
0072 uint64_t Size = 0, Align ByteAlignment = Align(1),
0073 SMLoc L = SMLoc()) override;
0074 void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
0075 Align ByteAlignment = Align(1)) override;
0076 void emitValueImpl(const MCExpr *Value, unsigned Size,
0077 SMLoc Loc = SMLoc()) override;
0078
0079 void emitIdent(StringRef IdentString) override;
0080
0081 void emitValueToAlignment(Align, int64_t, unsigned, unsigned) override;
0082
0083 void emitCGProfileEntry(const MCSymbolRefExpr *From,
0084 const MCSymbolRefExpr *To, uint64_t Count) override;
0085
0086
0087
0088 void finishImpl() final;
0089
0090 void emitBundleAlignMode(Align Alignment) override;
0091 void emitBundleLock(bool AlignToEnd) override;
0092 void emitBundleUnlock() override;
0093
0094
0095 struct AttributeItem {
0096
0097
0098
0099 enum Types {
0100 HiddenAttribute = 0,
0101 NumericAttribute,
0102 TextAttribute,
0103 NumericAndTextAttributes
0104 } Type;
0105 unsigned Tag;
0106 unsigned IntValue;
0107 std::string StringValue;
0108 AttributeItem(Types Ty, unsigned Tg, unsigned IV, std::string SV)
0109 : Type(Ty), Tag(Tg), IntValue(IV), StringValue(SV) {}
0110 };
0111
0112
0113 struct AttributeSubSection {
0114 bool IsActive;
0115 StringRef VendorName;
0116 unsigned IsOptional;
0117 unsigned ParameterType;
0118 SmallVector<AttributeItem, 64> Content;
0119 };
0120
0121
0122 SmallVector<AttributeItem, 64> Contents;
0123 void setAttributeItem(unsigned Attribute, unsigned Value,
0124 bool OverwriteExisting);
0125 void setAttributeItem(unsigned Attribute, StringRef Value,
0126 bool OverwriteExisting);
0127 void setAttributeItems(unsigned Attribute, unsigned IntValue,
0128 StringRef StringValue, bool OverwriteExisting);
0129 void emitAttributesSection(StringRef Vendor, const Twine &Section,
0130 unsigned Type, MCSection *&AttributeSection) {
0131 createAttributesSection(Vendor, Section, Type, AttributeSection, Contents);
0132 }
0133 void
0134 emitAttributesSection(MCSection *&AttributeSection, const Twine &Section,
0135 unsigned Type,
0136 SmallVector<AttributeSubSection, 64> &SubSectionVec) {
0137 createAttributesWithSubsection(AttributeSection, Section, Type,
0138 SubSectionVec);
0139 }
0140
0141 private:
0142 AttributeItem *getAttributeItem(unsigned Attribute);
0143 size_t calculateContentSize(SmallVector<AttributeItem, 64> &AttrsVec) const;
0144 void createAttributesSection(StringRef Vendor, const Twine &Section,
0145 unsigned Type, MCSection *&AttributeSection,
0146 SmallVector<AttributeItem, 64> &AttrsVec);
0147 void createAttributesWithSubsection(
0148 MCSection *&AttributeSection, const Twine &Section, unsigned Type,
0149 SmallVector<AttributeSubSection, 64> &SubSectionVec);
0150
0151
0152 SmallVector<AttributeItem, 64> GNUAttributes;
0153
0154 public:
0155 void emitGNUAttribute(unsigned Tag, unsigned Value) override {
0156 AttributeItem Item = {AttributeItem::NumericAttribute, Tag, Value,
0157 std::string(StringRef(""))};
0158 GNUAttributes.push_back(Item);
0159 }
0160
0161 private:
0162 bool isBundleLocked() const;
0163 void emitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override;
0164 void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
0165
0166 void fixSymbolsInTLSFixups(const MCExpr *expr);
0167 void finalizeCGProfileEntry(const MCSymbolRefExpr *&S, uint64_t Offset);
0168 void finalizeCGProfile();
0169
0170 bool SeenIdent = false;
0171 };
0172
0173 MCELFStreamer *createARMELFStreamer(MCContext &Context,
0174 std::unique_ptr<MCAsmBackend> TAB,
0175 std::unique_ptr<MCObjectWriter> OW,
0176 std::unique_ptr<MCCodeEmitter> Emitter,
0177 bool IsThumb, bool IsAndroid);
0178
0179 }
0180
0181 #endif