LLVM 23.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
45 ELFObjectWriter &getWriter();
46
47 /// \name MCStreamer Interface
48 /// @{
49
50 void initSections(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;
57 void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
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
64 void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
65 Align ByteAlignment) override;
66
67 void emitIdent(StringRef IdentString) override;
68
69 void emitCGProfileEntry(const MCSymbolRefExpr *From,
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.
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
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
151LLVM_ABI MCELFStreamer *
152createARMELFStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> TAB,
153 std::unique_ptr<MCObjectWriter> OW,
154 std::unique_ptr<MCCodeEmitter> Emitter, bool IsThumb,
155 bool IsAndroid);
156
157} // end namespace llvm
158
159#endif // LLVM_MC_MCELFSTREAMER_H
#define LLVM_ABI
Definition Compiler.h:213
dxil DXContainer Global Emitter
#define F(x, y, z)
Definition MD5.cpp:54
This file defines the SmallVector class.
static const uint32_t IV[8]
Definition blake3_impl.h:83
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
Generic interface to target specific assembler backends.
MCCodeEmitter - Generic instruction encoding interface.
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 setAttributeItems(unsigned Attribute, unsigned IntValue, StringRef StringValue, bool OverwriteExisting)
~MCELFStreamer() override=default
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 reset() override
state management
MCELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
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:188
void reset() override
state management
MCObjectStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Defines the object file and target independent interfaces used by the assembler backend to write nati...
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:573
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:22
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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:46
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:558
LLVM_ABI MCELFStreamer * createARMELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter, bool IsThumb, bool IsAndroid)
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
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:1916
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:860
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.
AttributeItem(Types Ty, unsigned Tg, unsigned IV, std::string SV)
enum llvm::MCELFStreamer::AttributeItem::Types Type
ELF object attributes subsection support.
SmallVector< AttributeItem, 64 > Content