LLVM 21.0.0git
MCELFStreamer.h
Go to the documentation of this file.
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
9#ifndef LLVM_MC_MCELFSTREAMER_H
10#define LLVM_MC_MCELFSTREAMER_H
11
15
16namespace llvm {
17
18class ELFObjectWriter;
19class MCContext;
20class MCDataFragment;
21class MCFragment;
22class MCObjectWriter;
23class MCSection;
24class MCSubtargetInfo;
25class MCSymbol;
26class MCSymbolRefExpr;
27class MCAsmBackend;
28class MCCodeEmitter;
29class MCExpr;
30class MCInst;
31
33public:
34 MCELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
35 std::unique_ptr<MCObjectWriter> OW,
36 std::unique_ptr<MCCodeEmitter> Emitter);
37
38 ~MCELFStreamer() override = default;
39
40 /// state management
41 void reset() override {
42 SeenIdent = false;
44 }
45
47
48 /// \name MCStreamer Interface
49 /// @{
50
51 void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override;
52 void changeSection(MCSection *Section, uint32_t Subsection = 0) override;
53 void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
54 void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F,
55 uint64_t Offset) override;
56 void emitAssemblerFlag(MCAssemblerFlag Flag) override;
57 void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
58 bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
59 void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
61 Align ByteAlignment) override;
62
63 void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
64 void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name,
65 bool KeepOriginalSym) override;
66
68 Align ByteAlignment) override;
69
70 void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
71 uint64_t Size = 0, Align ByteAlignment = Align(1),
72 SMLoc L = SMLoc()) override;
73 void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
74 Align ByteAlignment = Align(1)) override;
75 void emitValueImpl(const MCExpr *Value, unsigned Size,
76 SMLoc Loc = SMLoc()) override;
77
78 void emitIdent(StringRef IdentString) override;
79
80 void emitValueToAlignment(Align, int64_t, unsigned, unsigned) override;
81
83 const MCSymbolRefExpr *To, uint64_t Count) override;
84
85 // This is final. Override MCTargetStreamer::finish instead for
86 // target-specific code.
87 void finishImpl() final;
88
89 void emitBundleAlignMode(Align Alignment) override;
90 void emitBundleLock(bool AlignToEnd) override;
91 void emitBundleUnlock() override;
92
93 /// ELF object attributes section emission support
95 // This structure holds all attributes, accounting for their string /
96 // numeric value, so we can later emit them in declaration order, keeping
97 // all in the same vector.
98 enum Types {
99 HiddenAttribute = 0,
102 NumericAndTextAttributes
104 unsigned Tag;
105 unsigned IntValue;
106 std::string StringValue;
107 AttributeItem(Types Ty, unsigned Tg, unsigned IV, std::string SV)
108 : Type(Ty), Tag(Tg), IntValue(IV), StringValue(std::move(SV)) {}
109 };
110
111 /// ELF object attributes subsection support
115 unsigned IsOptional;
118 };
119
120 // Attributes that are added and managed entirely by target.
122 void setAttributeItem(unsigned Attribute, unsigned Value,
123 bool OverwriteExisting);
125 bool OverwriteExisting);
126 void setAttributeItems(unsigned Attribute, unsigned IntValue,
127 StringRef StringValue, bool OverwriteExisting);
128 void emitAttributesSection(StringRef Vendor, const Twine &Section,
129 unsigned Type, MCSection *&AttributeSection) {
130 createAttributesSection(Vendor, Section, Type, AttributeSection, Contents);
131 }
132 void
133 emitAttributesSection(MCSection *&AttributeSection, const Twine &Section,
134 unsigned Type,
136 createAttributesWithSubsection(AttributeSection, Section, Type,
137 SubSectionVec);
138 }
139
140private:
141 AttributeItem *getAttributeItem(unsigned Attribute);
142 size_t calculateContentSize(SmallVector<AttributeItem, 64> &AttrsVec) const;
143 void createAttributesSection(StringRef Vendor, const Twine &Section,
144 unsigned Type, MCSection *&AttributeSection,
146 void createAttributesWithSubsection(
147 MCSection *&AttributeSection, const Twine &Section, unsigned Type,
149
150 // GNU attributes that will get emitted at the end of the asm file.
151 SmallVector<AttributeItem, 64> GNUAttributes;
152
153public:
154 void emitGNUAttribute(unsigned Tag, unsigned Value) override {
156 std::string(StringRef(""))};
157 GNUAttributes.push_back(Item);
158 }
159
160private:
161 bool isBundleLocked() const;
162 void emitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override;
163 void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
164
165 void fixSymbolsInTLSFixups(const MCExpr *expr);
166 void finalizeCGProfileEntry(const MCSymbolRefExpr *&S, uint64_t Offset);
167 void finalizeCGProfile();
168
169 bool SeenIdent = false;
170};
171
172MCELFStreamer *createARMELFStreamer(MCContext &Context,
173 std::unique_ptr<MCAsmBackend> TAB,
174 std::unique_ptr<MCObjectWriter> OW,
175 std::unique_ptr<MCCodeEmitter> Emitter,
176 bool IsThumb, bool IsAndroid);
177
178} // end namespace llvm
179
180#endif // LLVM_MC_MCELFSTREAMER_H
BlockVerifier::State From
dxil DXContainer Global Emitter
std::string Name
uint64_t Size
#define F(x, y, z)
Definition: MD5.cpp:55
This file defines the SmallVector class.
static const uint32_t IV[8]
Definition: blake3_impl.h:78
Context object for machine code objects.
Definition: MCContext.h:83
Fragment for data and encoded instructions.
Definition: MCFragment.h:213
void emitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
SmallVector< AttributeItem, 64 > Contents
void emitAttributesSection(StringRef Vendor, const Twine &Section, unsigned Type, MCSection *&AttributeSection)
void emitValueToAlignment(Align, int64_t, unsigned, unsigned) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void changeSection(MCSection *Section, uint32_t Subsection=0) override
This is called by popSection and switchSection, if the current section changes.
void emitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
void setAttributeItems(unsigned Attribute, unsigned IntValue, StringRef StringValue, bool OverwriteExisting)
void emitBundleUnlock() override
Ends a bundle-locked group.
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a common symbol.
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a local common (.lcomm) symbol.
void emitAssemblerFlag(MCAssemblerFlag Flag) override
Note in the output the specified Flag.
void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override
Set the DescValue for the Symbol.
void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override
Emit an ELF .size directive.
void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name, bool KeepOriginalSym) override
Emit an ELF .symver directive.
~MCELFStreamer() override=default
void emitCGProfileEntry(const MCSymbolRefExpr *From, const MCSymbolRefExpr *To, uint64_t Count) override
ELFObjectWriter & getWriter()
void emitGNUAttribute(unsigned Tag, unsigned Value) override
Emit a .gnu_attribute directive.
void emitZerofill(MCSection *Section, MCSymbol *Symbol=nullptr, uint64_t Size=0, Align ByteAlignment=Align(1), SMLoc L=SMLoc()) override
Emit the zerofill section and an optional symbol.
void emitAttributesSection(MCSection *&AttributeSection, const Twine &Section, unsigned Type, SmallVector< AttributeSubSection, 64 > &SubSectionVec)
void setAttributeItem(unsigned Attribute, unsigned Value, bool OverwriteExisting)
void finishImpl() final
Streamer specific finalization.
void reset() override
state management
Definition: MCELFStreamer.h:41
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void emitBundleAlignMode(Align Alignment) override
Set the bundle alignment mode from now on in the section.
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, Align ByteAlignment=Align(1)) override
Emit a thread local bss (.tbss) symbol.
void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override
Create the default sections and set the initial one.
void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCDataFragment &F, uint64_t Offset) override
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:185
Streaming object file generation interface.
void reset() override
state management
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:36
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Represents a location in source code.
Definition: SMLoc.h:23
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
MCELFStreamer * createARMELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter, bool IsThumb, bool IsAndroid)
MCAssemblerFlag
Definition: MCDirectives.h:53
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1873
MCSymbolAttr
Definition: MCDirectives.h:18
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
ELF object attributes section emission support.
Definition: MCELFStreamer.h:94
AttributeItem(Types Ty, unsigned Tg, unsigned IV, std::string SV)
ELF object attributes subsection support.
SmallVector< AttributeItem, 64 > Content