1//===- MCSection.h - Machine Code Sections ----------------------*- C++ -*-===//
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
7//===----------------------------------------------------------------------===//
9// This file declares the MCSection class.
11//===----------------------------------------------------------------------===//
13#ifndef LLVM_MC_MCSECTION_H
14#define LLVM_MC_MCSECTION_H
42// Represents a contiguous piece of code or data within a section. Its size is
43// determined by MCAssembler::layout. All subclasses must have trivial
70 // The next fragment within the section.
73 /// The data for the section this fragment is in.
76 /// The offset of this fragment in its section.
79 /// The layout order of this fragment.
80 unsigned LayoutOrder = 0;
84 //== Used by certain fragment types for better packing.
86 // The number of fixups for the optional variable-size tail must be small.
89 bool LinkerRelaxable : 1;
91 /// FT_Data, FT_Relaxable
92 bool HasInstructions : 1;
93 /// FT_Relaxable, x86-specific
94 bool AllowAutoPadding : 1;
96 // Track content and fixups for the fixed-size part as fragments are
97 // appended to the section. The content is stored as trailing data of the
98 // MCFragment. The content remains immutable, except when modified by
104 // Track content and fixups for the optional variable-size tail part,
105 // typically modified during relaxation.
114 // Optional variable-size tail used by various fragment types.
123 // The alignment to ensure, in bytes.
125 // The size of the integer (in bytes) of \p Value.
127 // If true, fill with target-specific nop instructions.
129 // The maximum number of bytes to emit; if the alignment
130 // cannot be satisfied in this width then this fragment is ignored.
131 unsigned MaxBytesToEmit;
132 // Value to use for filling padding bytes.
136 // True if this is a sleb128, false if uleb128.
138 // The value this fragment should contain.
141 // Used by .debug_frame and .debug_line to encode an address difference.
143 // The address difference between two labels.
145 // The value of the difference between the two line numbers between two
146 // .loc dwarf directives.
150 // This FRE describes unwind info at AddrDelta from function start.
152 // Fragment that records how many bytes of AddrDelta to emit.
159 bool HasInstructions =
false);
175 /// Does this fragment have instructions emitted into it? By default
176 /// this is false, but specific fragment types may set it to true.
181 /// Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
182 /// Guaranteed to be non-null if hasInstructions() == true
185 /// Record that the fragment contains instructions with the MCSubtargetInfo in
186 /// effect when the instruction was encoded.
188 HasInstructions =
true;
198 //== Content-related functions manage parent's storage using ContentStart and
210 size_t getVarSize()
const {
return VarContentEnd - VarContentStart; }
212 return FixedSize + (VarContentEnd - VarContentStart);
215 //== Fixup-related functions manage parent's storage using FixupStart and
223 // Source fixup offsets are relative to the variable part's start.
224 // Stored fixup offsets are relative to the fixed part's start.
230 //== FT_Relaxable functions
233 return u.relax.Opcode;
239 //== FT_Align functions
241 unsigned MaxBytesToEmit) {
243 u.align.EmitNops =
false;
244 u.align.Alignment = Alignment;
246 u.align.FillLen = FillLen;
247 u.align.MaxBytesToEmit = MaxBytesToEmit;
252 return u.align.Alignment;
260 return u.align.FillLen;
264 return u.align.MaxBytesToEmit;
268 return u.align.EmitNops;
271 //== FT_LEB functions
275 u.leb.IsSigned = IsSigned;
288 return u.leb.IsSigned;
291 //== FT_DwarfFrame functions
294 return *u.dwarf.AddrDelta;
298 u.dwarf.AddrDelta =
E;
302 return u.dwarf.LineDelta;
306 u.dwarf.LineDelta = LineDelta;
309 //== FT_SFrame functions
312 return *u.sframe.AddrDelta;
316 u.sframe.AddrDelta =
E;
320 return u.sframe.FDEFragment;
324 u.sframe.FDEFragment =
F;
328// MCFragment subclasses do not use the fixed-size part or variable-size tail of
329// MCFragment. Instead, they encode content in a specialized way.
333 /// Value to use for filling bytes.
335 /// The number of bytes to insert.
338 /// Source location of the directive that this fragment was created for.
345 NumValues(NumValues), Loc(Loc) {}
359 /// The number of bytes to insert.
361 /// Maximum number of bytes allowed in each NOP instruction.
362 int64_t ControlledNopLength;
364 /// Source location of the directive that this fragment was created for.
371 ControlledNopLength(ControlledNopLength), Loc(L) {
386 /// Value to use for filling bytes.
389 /// The offset this fragment should start at.
392 /// Source location of the directive that this fragment was created for.
409/// Represents a symbol table index fragment.
424/// Fragment representing the binary annotations produced by the
425/// .cv_inline_linetable directive.
428 unsigned StartFileId;
429 unsigned StartLineNum;
433 /// CodeViewContext has the real knowledge about this format, so let it access
439 unsigned StartLineNum,
const MCSymbol *FnStartSym,
442 StartFileId(StartFileId), StartLineNum(StartLineNum),
443 FnStartSym(FnStartSym), FnEndSym(FnEndSym) {}
453/// Fragment representing the .cv_def_range directive.
458 /// CodeViewContext has the real knowledge about this format, so let it access
464 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
467 FixedSizePortion(FixedSizePortion) {}
480/// Represents required padding such that a particular other set of fragments
481/// does not cross a particular power-of-two boundary. The other fragments must
482/// follow this one within the same section.
484 /// The alignment requirement of the branch to be aligned.
486 /// The last fragment in the set of fragments to be aligned.
488 /// The size of the fragment. The size is lazily set during relaxation, and
489 /// is not meaningful before that.
515/// Instances of this class represent a uniqued identifier for a section in the
516/// current translation unit. The MCContext class uniques and creates these.
540 // At parse time, this holds the fragment list of the current subsection. At
541 // layout time, this holds the concatenated fragment lists of all subsections.
543 // In many object file formats, this denotes the section symbol. In Mach-O,
544 // this denotes an optional temporary label at the section start.
547 /// The alignment requirement of this section.
549 /// The section index in the assemblers section list.
550 unsigned Ordinal = 0;
551 // If not -1u, the first linker-relaxable fragment's order within the
552 // subsection. When present, the offset between two locations crossing this
553 // fragment may not be fully resolved.
554 unsigned FirstLinkerRelaxable = -1u;
556 /// Whether this section has had instructions emitted into it.
557 bool HasInstructions : 1;
559 bool IsRegistered : 1;
566 // Mapping from subsection number to fragment list. At layout time, the
567 // subsection 0 list is replaced with concatenated fragments from all
571 // Content and fixup storage for fragments
577 // TODO Make Name private when possible.
598 bool hasEnded()
const;
603 /// Makes sure that Alignment is at least MinAlignment.
605 if (Alignment < MinAlignment)
606 Alignment = MinAlignment;
629 *FragToSyms =
nullptr)
const;
631 /// Check whether this section is "virtual", that is has no actual object
637 return {
reinterpret_cast<char *
>(
this + 1), FixedSize};
640 return {
reinterpret_cast<const char *
>(
this + 1), FixedSize};
645 .
slice(VarContentStart, VarContentEnd - VarContentStart);
649 .
slice(VarContentStart, VarContentEnd - VarContentStart);
652//== Fixup-related functions manage parent's storage using FixupStart and
656 .
slice(FixupStart, FixupEnd - FixupStart);
660 .
slice(FixupStart, FixupEnd - FixupStart);
665 .
slice(VarFixupStart, VarFixupSize);
671//== FT_Relaxable functions
675 .slice(u.relax.OperandStart, u.relax.OperandSize);
683 .slice(u.relax.OperandStart, u.relax.OperandSize));
692 u.relax.OperandStart = S.size();
704}
// end namespace llvm
706#endif // LLVM_MC_MCSECTION_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
PowerPC TLS Dynamic Call Fixup
This file defines the SmallString class.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
This class is intended to be used as a base class for asm properties and features specific to the tar...
MCBoundaryAlignFragment(Align AlignBoundary, const MCSubtargetInfo &STI)
void setAlignment(Align Value)
void setSize(uint64_t Value)
const MCFragment * getLastFragment() const
static bool classof(const MCFragment *F)
Align getAlignment() const
void setLastFragment(const MCFragment *F)
MCCVDefRangeFragment(ArrayRef< std::pair< const MCSymbol *, const MCSymbol * > > Ranges, StringRef FixedSizePortion)
ArrayRef< std::pair< const MCSymbol *, const MCSymbol * > > getRanges() const
static bool classof(const MCFragment *F)
StringRef getFixedSizePortion() const
friend class CodeViewContext
CodeViewContext has the real knowledge about this format, so let it access our members.
static bool classof(const MCFragment *F)
MCCVInlineLineTableFragment(unsigned SiteFuncId, unsigned StartFileId, unsigned StartLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
const MCSymbol * getFnStartSym() const
friend class CodeViewContext
CodeViewContext has the real knowledge about this format, so let it access our members.
const MCSymbol * getFnEndSym() const
Context object for machine code objects.
Base class for the full range of assembler expressions which are needed for parsing.
MCFillFragment(uint64_t Value, uint8_t VSize, const MCExpr &NumValues, SMLoc Loc)
uint8_t getValueSize() const
uint64_t getValue() const
static bool classof(const MCFragment *F)
const MCExpr & getNumValues() const
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
const MCExpr & getDwarfAddrDelta() const
MutableArrayRef< char > getContents()
MCFragment * getSFrameFDE() const
bool getAllowAutoPadding() const
FragmentType getKind() const
bool isLinkerRelaxable() const
void setAllowAutoPadding(bool V)
unsigned getLayoutOrder() const
LLVM_ABI MCFragment(FragmentType Kind=MCFragment::FT_Data, bool HasInstructions=false)
bool hasAlignEmitNops() const
friend class MCObjectStreamer
void setSFrameAddrDelta(const MCExpr *E)
void setParent(MCSection *Value)
LLVM_ABI const MCSymbol * getAtom() const
LLVM_ABI void appendFixups(ArrayRef< MCFixup > Fixups)
void setDwarfLineDelta(int64_t LineDelta)
unsigned getAlignMaxBytesToEmit() const
int64_t getDwarfLineDelta() const
unsigned getOpcode() const
MutableArrayRef< MCFixup > getFixups()
void setLayoutOrder(unsigned Value)
void setSFrameFDE(MCFragment *F)
const MCExpr & getLEBValue() const
LLVM_ABI void dump() const
MCSection * getParent() const
void makeAlign(Align Alignment, int64_t Fill, uint8_t FillLen, unsigned MaxBytesToEmit)
LLVM_ABI void setVarFixups(ArrayRef< MCFixup > Fixups)
MCFragment * getNext() const
const MCSubtargetInfo * STI
MCFragment(const MCFragment &)=delete
ArrayRef< MCOperand > getOperands() const
LLVM_ABI void addFixup(MCFixup Fixup)
void setLinkerRelaxable()
Align getAlignment() const
size_t getFixedSize() const
int64_t getAlignFill() const
MCFragment & operator=(const MCFragment &)=delete
void makeLEB(bool IsSigned, const MCExpr *Value)
bool hasInstructions() const
Does this fragment have instructions emitted into it?
uint8_t getAlignFillLen() const
void setDwarfAddrDelta(const MCExpr *E)
void setLEBValue(const MCExpr *Expr)
size_t getVarSize() const
LLVM_ABI void setVarContents(ArrayRef< char > Contents)
MutableArrayRef< char > getVarContents()
const MCSubtargetInfo * getSubtargetInfo() const
Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
void setHasInstructions(const MCSubtargetInfo &STI)
Record that the fragment contains instructions with the MCSubtargetInfo in effect when the instructio...
const MCExpr & getSFrameAddrDelta() const
MutableArrayRef< MCFixup > getVarFixups()
void setInst(const MCInst &Inst)
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
unsigned getFlags() const
unsigned getOpcode() const
void setFlags(unsigned F)
void setOperands(ArrayRef< MCOperand > Ops)
void setOpcode(unsigned Op)
int64_t getControlledNopLength() const
int64_t getNumBytes() const
MCNopsFragment(int64_t NumBytes, int64_t ControlledNopLength, SMLoc L, const MCSubtargetInfo &STI)
static bool classof(const MCFragment *F)
Streaming object file generation interface.
static bool classof(const MCFragment *F)
const MCExpr & getOffset() const
MCOrgFragment(const MCExpr &Offset, int8_t Value, SMLoc Loc)
Instances of this class represent a uniqued identifier for a section in the current translation unit.
void setAlignment(Align Value)
unsigned getOrdinal() const
void ensureMinAlignment(Align MinAlignment)
Makes sure that Alignment is at least MinAlignment.
bool isBssSection() const
Check whether this section is "virtual", that is has no actual object file contents.
bool isLinkerRelaxable() const
static constexpr unsigned NonUniqueID
const MCSymbol * getBeginSymbol() const
bool hasInstructions() const
bool isRegistered() const
void setHasInstructions(bool Value)
void setBeginSymbol(MCSymbol *Sym)
MCSection(const MCSection &)=delete
void setOrdinal(unsigned Value)
MCSection & operator=(const MCSection &)=delete
StringRef getName() const
MCFragment & getDummyFragment()
unsigned firstLinkerRelaxable() const
FragList * curFragList() const
MCSymbol * getBeginSymbol()
MCSection(StringRef Name, bool IsText, bool IsBss, MCSymbol *Begin)
void setIsRegistered(bool Value)
void setFirstLinkerRelaxable(unsigned Order)
Generic base class for all target subtargets.
const MCSymbol * getSymbol() const
MCSymbolIdFragment(const MCSymbol *Sym)
static bool classof(const MCFragment *F)
const MCSymbol * getSymbol()
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
MutableArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Represents a location in source code.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
Calculates the starting offsets for various sections within the .debug_names section.
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
FunctionAddr VTableAddr Next
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
This struct is a compact representation of a valid (non-zero power of two) alignment.
MCFragment & operator*() const
bool operator==(const iterator &O) const
bool operator!=(const iterator &O) const