LLVM 22.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 MCFragment;
21class MCObjectWriter;
22class MCSection;
23class MCSubtargetInfo;
24class MCSymbol;
25class MCSymbolRefExpr;
26class MCAsmBackend;
27class MCCodeEmitter;
28class MCExpr;
29class MCInst;
30
32public:
33 MCELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
34 std::unique_ptr<MCObjectWriter> OW,
35 std::unique_ptr<MCCodeEmitter> Emitter);
36
37 ~MCELFStreamer() override = default;
38
39 /// state management
40 void reset() override {
41 SeenIdent = false;
43 }
44
46
47 /// \name MCStreamer Interface
48 /// @{
49
50 void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override;
51 void changeSection(MCSection *Section, uint32_t Subsection = 0) override;
52 void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
53 void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment &F,
54 uint64_t Offset) override;
55 void emitWeakReference(MCSymbol *Alias, const MCSymbol *Target) override;
56 bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
58 Align ByteAlignment) override;
59
60 void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override;
61 void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name,
62 bool KeepOriginalSym) override;
63
65 Align ByteAlignment) override;
66
67 void emitIdent(StringRef IdentString) override;
68
70 const MCSymbolRefExpr *To, uint64_t Count) override;
71
72 // This is final. Override MCTargetStreamer::finish instead for
73 // target-specific code.
74 void finishImpl() final;
75
76 /// ELF object attributes section emission support
78 // This structure holds all attributes, accounting for their string /
79 // numeric value, so we can later emit them in declaration order, keeping
80 // all in the same vector.
81 enum Types {
82 HiddenAttribute = 0,
85 NumericAndTextAttributes
87 unsigned Tag;
88 unsigned IntValue;
89 std::string StringValue;
90 AttributeItem(Types Ty, unsigned Tg, unsigned IV, std::string SV)
91 : Type(Ty), Tag(Tg), IntValue(IV), StringValue(std::move(SV)) {}
92 };
93
94 /// ELF object attributes subsection support
98 unsigned IsOptional;
99 unsigned ParameterType;
101 };
102
103 // Attributes that are added and managed entirely by target.
105 void setAttributeItem(unsigned Attribute, unsigned Value,
106 bool OverwriteExisting);
108 bool OverwriteExisting);
109 void setAttributeItems(unsigned Attribute, unsigned IntValue,
110 StringRef StringValue, bool OverwriteExisting);
111 void emitAttributesSection(StringRef Vendor, const Twine &Section,
112 unsigned Type, MCSection *&AttributeSection) {
113 createAttributesSection(Vendor, Section, Type, AttributeSection, Contents);
114 }
115 void
116 emitAttributesSection(MCSection *&AttributeSection, const Twine &Section,
117 unsigned Type,
119 createAttributesWithSubsection(AttributeSection, Section, Type,
120 SubSectionVec);
121 }
122
123private:
124 AttributeItem *getAttributeItem(unsigned Attribute);
125 size_t calculateContentSize(SmallVector<AttributeItem, 64> &AttrsVec) const;
126 void createAttributesSection(StringRef Vendor, const Twine &Section,
127 unsigned Type, MCSection *&AttributeSection,
129 void createAttributesWithSubsection(
130 MCSection *&AttributeSection, const Twine &Section, unsigned Type,
132
133 // GNU attributes that will get emitted at the end of the asm file.
134 SmallVector<AttributeItem, 64> GNUAttributes;
135
136public:
137 void emitGNUAttribute(unsigned Tag, unsigned Value) override {
139 std::string(StringRef(""))};
140 GNUAttributes.push_back(Item);
141 }
142
143private:
144 void finalizeCGProfileEntry(const MCSymbolRefExpr *Sym, uint64_t Offset,
145 const MCSymbolRefExpr *&S);
146 void finalizeCGProfile();
147
148 bool SeenIdent = false;
149};
150
151MCELFStreamer *createARMELFStreamer(MCContext &Context,
152 std::unique_ptr<MCAsmBackend> TAB,
153 std::unique_ptr<MCObjectWriter> OW,
154 std::unique_ptr<MCCodeEmitter> Emitter,
155 bool IsThumb, bool IsAndroid);
156
157} // end namespace llvm
158
159#endif // LLVM_MC_MCELFSTREAMER_H
BlockVerifier::State From
dxil DXContainer Global Emitter
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
#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:83
Context object for machine code objects.
Definition: MCContext.h:83
SmallVector< AttributeItem, 64 > Contents
void emitAttributesSection(StringRef Vendor, const Twine &Section, unsigned Type, MCSection *&AttributeSection)
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 emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a common symbol.
void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment) override
Emit a local common (.lcomm) symbol.
void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override
Emit an ELF .size directive.
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Target) override
Emit an weak reference from Alias to Symbol.
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
void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment &F, uint64_t Offset) override
ELFObjectWriter & getWriter()
void emitGNUAttribute(unsigned Tag, unsigned Value) override
Emit a .gnu_attribute directive.
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:40
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override
Create the default sections and set the initial one.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
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:496
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:190
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
Represents a location in source code.
Definition: SMLoc.h:23
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
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:75
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
MCELFStreamer * createARMELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter, bool IsThumb, bool IsAndroid)
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:1886
MCSymbolAttr
Definition: MCDirectives.h:18
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
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:77
AttributeItem(Types Ty, unsigned Tg, unsigned IV, std::string SV)
Definition: MCELFStreamer.h:90
ELF object attributes subsection support.
Definition: MCELFStreamer.h:95
SmallVector< AttributeItem, 64 > Content