48 #define DEBUG_TYPE "assembler" 53 STATISTIC(EmittedFragments,
"Number of emitted assembler fragments - total");
55 "Number of emitted assembler fragments - relaxable");
57 "Number of emitted assembler fragments - data");
58 STATISTIC(EmittedCompactEncodedInstFragments,
59 "Number of emitted assembler fragments - compact encoded inst");
61 "Number of emitted assembler fragments - align");
63 "Number of emitted assembler fragments - fill");
65 "Number of emitted assembler fragments - org");
66 STATISTIC(evaluateFixup,
"Number of evaluated fixups");
67 STATISTIC(FragmentLayouts,
"Number of fragment layouts");
68 STATISTIC(ObjectBytes,
"Number of emitted object file bytes");
69 STATISTIC(RelaxationSteps,
"Number of assembler layout and relaxation steps");
70 STATISTIC(RelaxedInstructions,
"Number of relaxed instructions");
83 std::unique_ptr<MCAsmBackend> Backend,
84 std::unique_ptr<MCCodeEmitter> Emitter,
85 std::unique_ptr<MCObjectWriter> Writer)
86 : Context(Context), Backend(
std::move(Backend)),
87 Emitter(
std::move(Emitter)), Writer(
std::move(Writer)),
88 BundleAlignSize(0), RelaxAll(
false), SubsectionsViaSymbols(
false),
89 IncrementalLinkerCompatible(
false), ELFHeaderEFlags(0) {
90 VersionInfo.Major = 0;
98 IndirectSymbols.clear();
100 LinkerOptions.clear();
105 SubsectionsViaSymbols =
false;
106 IncrementalLinkerCompatible =
false;
108 LOHContainer.
reset();
109 VersionInfo.Major = 0;
125 Sections.push_back(&Section);
131 if (ThumbFuncs.count(Symbol))
157 ThumbFuncs.insert(Symbol);
191 bool MCAssembler::evaluateFixup(
const MCAsmLayout &Layout,
194 bool &WasForced)
const {
195 ++stats::evaluateFixup;
214 "unsupported subtraction of qualified symbol");
231 bool IsResolved =
false;
235 }
else if (!Target.
getSymA()) {
244 Writer->isSymbolRefDifferenceFullyResolvedImpl(
245 *
this, SA, *DF,
false,
true);
255 const MCSymbol &Sym = A->getSymbol();
267 assert((ShouldAlignPC ? IsPCRel :
true) &&
268 "FKF_IsAlignedDownTo32Bits is only allowed on PC-relative fixups!");
275 if (ShouldAlignPC) Offset &= ~0x3;
280 if (IsResolved &&
getBackend().shouldForceRelocation(*
this, Fixup, Target)) {
293 return cast<MCDataFragment>(
F).getContents().size();
295 return cast<MCRelaxableFragment>(
F).getContents().size();
297 return cast<MCCompactEncodedInstFragment>(
F).getContents().size();
299 auto &FF = cast<MCFillFragment>(
F);
300 int64_t NumValues = 0;
301 if (!FF.getNumValues().evaluateAsAbsolute(NumValues, Layout)) {
303 "expected assembly-time absolute expression");
306 int64_t
Size = NumValues * FF.getValueSize();
315 return cast<MCLEBFragment>(
F).getContents().size();
318 return cast<MCBoundaryAlignFragment>(
F).getSize();
350 "expected assembly-time absolute expression");
355 int64_t TargetLocation = Value.getConstant();
362 TargetLocation += Val;
364 int64_t
Size = TargetLocation - FragmentOffset;
365 if (Size < 0 || Size >= 0x40000000) {
367 OF.
getLoc(),
"invalid .org offset '" +
Twine(TargetLocation) +
368 "' (at offset '" +
Twine(FragmentOffset) +
"')");
375 return cast<MCDwarfLineAddrFragment>(
F).getContents().size();
377 return cast<MCDwarfCallFrameFragment>(
F).getContents().size();
379 return cast<MCCVInlineLineTableFragment>(
F).getContents().size();
381 return cast<MCCVDefRangeFragment>(
F).getContents().size();
393 assert(!isFragmentValid(F) &&
"Attempt to recompute a valid fragment!");
396 assert((!Prev || isFragmentValid(Prev)) &&
397 "Attempt to compute fragment before its predecessor!");
399 ++stats::FragmentLayouts;
403 F->Offset = Prev->Offset + getAssembler().computeFragmentSize(*
this, *Prev);
436 assert(isa<MCEncodedFragment>(F) &&
437 "Only MCEncodedFragment implementations have instructions");
439 uint64_t FSize = Assembler.computeFragmentSize(*
this, *EF);
441 if (!Assembler.getRelaxAll() && FSize > Assembler.getBundleAlignSize())
444 uint64_t RequiredBundlePadding =
446 if (RequiredBundlePadding > UINT8_MAX)
449 EF->Offset += RequiredBundlePadding;
459 Symbols.push_back(&Symbol);
465 uint64_t FSize)
const {
469 if (BundlePadding > 0) {
471 "Writing bundle padding with disabled bundling");
473 "Writing bundle padding for a fragment without instructions");
475 unsigned TotalLength = BundlePadding +
static_cast<unsigned>(FSize);
486 if (!
getBackend().writeNopData(OS, DistanceToBoundary))
488 Twine(DistanceToBoundary) +
" bytes");
489 BundlePadding -= DistanceToBoundary;
491 if (!
getBackend().writeNopData(OS, BundlePadding))
493 Twine(BundlePadding) +
" bytes");
510 uint64_t Start = OS.
tell();
513 ++stats::EmittedFragments;
517 ++stats::EmittedAlignFragments;
529 "' is not a divisor of padding size '" +
530 Twine(FragmentSize) +
"'");
539 Twine(Count) +
" bytes");
544 for (uint64_t i = 0; i != Count; ++i) {
549 support::endian::write<uint16_t>(OS, AF.
getValue(), Endian);
552 support::endian::write<uint32_t>(OS, AF.
getValue(), Endian);
555 support::endian::write<uint64_t>(OS, AF.
getValue(), Endian);
563 ++stats::EmittedDataFragments;
564 OS << cast<MCDataFragment>(
F).getContents();
568 ++stats::EmittedRelaxableFragments;
569 OS << cast<MCRelaxableFragment>(
F).getContents();
573 ++stats::EmittedCompactEncodedInstFragments;
574 OS << cast<MCCompactEncodedInstFragment>(
F).getContents();
578 ++stats::EmittedFillFragments;
582 const unsigned MaxChunkSize = 16;
583 char Data[MaxChunkSize];
584 assert(0 < VSize && VSize <= MaxChunkSize &&
"Illegal fragment fill size");
587 for (
unsigned I = 0;
I != VSize; ++
I) {
589 Data[
I] = uint8_t(V >> (index * 8));
591 for (
unsigned I = VSize;
I < MaxChunkSize; ++
I)
592 Data[
I] = Data[
I - VSize];
595 const unsigned NumPerChunk = MaxChunkSize / VSize;
597 const unsigned ChunkSize = VSize * NumPerChunk;
601 for (uint64_t
I = 0,
E = FragmentSize / ChunkSize;
I !=
E; ++
I)
605 unsigned TrailingCount = FragmentSize % ChunkSize;
607 OS.
write(Data, TrailingCount);
620 Twine(FragmentSize) +
" bytes");
631 ++stats::EmittedOrgFragments;
634 for (uint64_t i = 0,
e = FragmentSize; i !=
e; ++i)
651 const auto &OF = cast<MCCVInlineLineTableFragment>(
F);
652 OS << OF.getContents();
656 const auto &DRF = cast<MCCVDefRangeFragment>(
F);
657 OS << DRF.getContents();
665 "The stream should advance by fragment size");
678 switch (
F.getKind()) {
689 if (
auto *ELFSec = dyn_cast<const MCSectionELF>(Sec))
691 ELFSec->getSectionName() +
"'");
700 assert((cast<MCAlignFragment>(
F).getValueSize() == 0 ||
701 cast<MCAlignFragment>(
F).getValue() == 0) &&
702 "Invalid align in virtual section!");
705 assert((cast<MCFillFragment>(
F).getValue() == 0) &&
706 "Invalid fill in virtual section!");
714 uint64_t Start = OS.
tell();
723 std::tuple<MCValue, uint64_t, bool>
730 bool IsResolved = evaluateFixup(Layout, Fixup, &F, Target, FixedValue,
757 return std::make_tuple(Target, FixedValue, IsResolved);
763 errs() <<
"assembler backend - pre-layout\n--\n";
767 unsigned SectionIndex = 0;
782 unsigned FragmentIndex = 0;
784 Frag.setLayoutOrder(FragmentIndex++);
788 while (layoutOnce(Layout))
793 errs() <<
"assembler backend - post-relaxation\n--\n";
797 finishLayout(Layout);
800 errs() <<
"assembler backend - final-layout\n--\n";
814 if (isa<MCEncodedFragment>(&Frag) &&
815 isa<MCCompactEncodedInstFragment>(&Frag))
817 if (!isa<MCEncodedFragment>(&Frag) && !isa<MCCVDefRangeFragment>(&Frag) &&
818 !isa<MCAlignFragment>(&Frag))
823 if (
auto *FragWithFixups = dyn_cast<MCDataFragment>(&Frag)) {
824 Fixups = FragWithFixups->getFixups();
825 Contents = FragWithFixups->getContents();
826 STI = FragWithFixups->getSubtargetInfo();
827 assert(!FragWithFixups->hasInstructions() || STI !=
nullptr);
828 }
else if (
auto *FragWithFixups = dyn_cast<MCRelaxableFragment>(&Frag)) {
829 Fixups = FragWithFixups->getFixups();
830 Contents = FragWithFixups->getContents();
831 STI = FragWithFixups->getSubtargetInfo();
832 assert(!FragWithFixups->hasInstructions() || STI !=
nullptr);
833 }
else if (
auto *FragWithFixups = dyn_cast<MCCVDefRangeFragment>(&Frag)) {
834 Fixups = FragWithFixups->getFixups();
835 Contents = FragWithFixups->getContents();
836 }
else if (
auto *FragWithFixups = dyn_cast<MCDwarfLineAddrFragment>(&Frag)) {
837 Fixups = FragWithFixups->getFixups();
838 Contents = FragWithFixups->getContents();
839 }
else if (
auto *AF = dyn_cast<MCAlignFragment>(&Frag)) {
842 if (Sec.UseCodeAlign() && AF->hasEmitNops()) {
846 }
else if (
auto *FragWithFixups =
847 dyn_cast<MCDwarfCallFrameFragment>(&Frag)) {
848 Fixups = FragWithFixups->getFixups();
849 Contents = FragWithFixups->getContents();
852 for (
const MCFixup &Fixup : Fixups) {
856 std::tie(Target, FixedValue, IsResolved) =
857 handleFixup(Layout, Frag, Fixup);
874 bool MCAssembler::fixupNeedsRelaxation(
const MCFixup &Fixup,
881 bool Resolved = evaluateFixup(Layout, Fixup, DF, Target, Value, WasForced);
900 if (fixupNeedsRelaxation(Fixup, F, Layout))
906 bool MCAssembler::relaxInstruction(
MCAsmLayout &Layout,
909 "Expected CodeEmitter defined for relaxInstruction");
910 if (!fragmentNeedsRelaxation(&F, Layout))
913 ++stats::RelaxedInstructions;
967 Align BoundaryAlignment) {
968 uint64_t EndAddr = StartAddr +
Size;
969 return (StartAddr >>
Log2(BoundaryAlignment)) !=
970 ((EndAddr - 1) >>
Log2(BoundaryAlignment));
980 Align BoundaryAlignment) {
981 uint64_t EndAddr = StartAddr +
Size;
982 return (EndAddr & (BoundaryAlignment.
value() - 1)) == 0;
992 Align BoundaryAlignment) {
997 bool MCAssembler::relaxBoundaryAlign(
MCAsmLayout &Layout,
1004 uint64_t AlignedSize = 0;
1009 for (
auto i = 0,
N = BF.
isFused() ? 2 : 1;
1010 i !=
N && !isa<MCBoundaryAlignFragment>(
F); ++i, F = F->
getNextNode()) {
1013 uint64_t OldSize = BF.
getSize();
1014 AlignedOffset -= OldSize;
1016 uint64_t NewSize =
needPadding(AlignedOffset, AlignedSize, BoundaryAlignment)
1019 if (NewSize == OldSize)
1026 bool MCAssembler::relaxDwarfLineAddr(
MCAsmLayout &Layout,
1032 assert(Abs &&
"We created a line delta with an invalid expression");
1041 if (!
getBackend().requiresDiffExpressionRelocations()) {
1049 LineDelta, AddrDelta,
1050 OSE, &Offset, &Size);
1057 FixupExpr = ABE->
getLHS();
1064 return OldSize != Data.
size();
1067 bool MCAssembler::relaxDwarfCallFrameFragment(
MCAsmLayout &Layout,
1073 assert(Abs &&
"We created call frame with an invalid expression");
1080 if (
getBackend().requiresDiffExpressionRelocations()) {
1094 return OldSize != Data.
size();
1097 bool MCAssembler::relaxCVInlineLineTable(
MCAsmLayout &Layout,
1104 bool MCAssembler::relaxCVDefRange(
MCAsmLayout &Layout,
1121 bool RelaxedFrag =
false;
1122 switch(
I->getKind()) {
1127 "Did not expect a MCRelaxableFragment in RelaxAll mode");
1128 RelaxedFrag = relaxInstruction(Layout, *cast<MCRelaxableFragment>(
I));
1131 RelaxedFrag = relaxDwarfLineAddr(Layout,
1132 *cast<MCDwarfLineAddrFragment>(
I));
1136 relaxDwarfCallFrameFragment(Layout,
1137 *cast<MCDwarfCallFrameFragment>(
I));
1140 RelaxedFrag = relaxLEB(Layout, *cast<MCLEBFragment>(
I));
1144 relaxBoundaryAlign(Layout, *cast<MCBoundaryAlignFragment>(
I));
1148 relaxCVInlineLineTable(Layout, *cast<MCCVInlineLineTableFragment>(
I));
1151 RelaxedFrag = relaxCVDefRange(Layout, *cast<MCCVDefRangeFragment>(
I));
1154 if (RelaxedFrag && !FirstRelaxedFragment)
1155 FirstRelaxedFragment = &*
I;
1157 if (FirstRelaxedFragment) {
1164 bool MCAssembler::layoutOnce(
MCAsmLayout &Layout) {
1165 ++stats::RelaxationSteps;
1167 bool WasRelaxed =
false;
1170 while (layoutSectionOnce(Layout, Sec))
1177 void MCAssembler::finishLayout(
MCAsmLayout &Layout) {
1180 for (
unsigned int i = 0, n = Layout.
getSectionOrder().size(); i != n; ++i) {
1188 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 1192 OS <<
"<MCAssembler\n";
1193 OS <<
" Sections:[\n ";
1195 if (it !=
begin()) OS <<
",\n ";
1205 OS <<
", Index:" << it->getIndex() <<
", ";
const MCAsmInfo * getAsmInfo() const
unsigned Log2(Align A)
Returns the log2 of the alignment.
virtual bool shouldInsertExtraNopBytesForCodeAlign(const MCAlignFragment &AF, unsigned &Size)
Hook to check if extra nop bytes must be inserted for alignment directive.
Instances of this class represent a uniqued identifier for a section in the current translation unit...
bool alignToBundleEnd() const
Should this fragment be placed at the end of an aligned bundle?
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
void encodeDefRange(MCAsmLayout &Layout, MCCVDefRangeFragment &F)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
uint32_t getIndex() const
Get the (implementation defined) index.
This fixup kind should be resolved if defined.
static void writeFragment(raw_ostream &OS, const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment &F)
Write the fragment F to the output file.
pointee_iterator< SectionListType::iterator > iterator
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
MCObjectWriter * getWriterPtr() const
bool isVariable() const
isVariable - Check if this is a variable symbol.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
This represents an "assembler immediate".
const support::endianness Endian
uint64_t getSectionAddressSize(const MCSection *Sec) const
Get the address space size of the given section, as it effects layout.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
VariantKind getKind() const
virtual bool requiresDiffExpressionRelocations() const
Check whether the given target requires emitting differences of two symbols as a set of relocations...
virtual void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, MCInst &Res) const =0
Relax the instruction in the given fragment to the next wider instruction.
uint8_t getValueSize() const
SmallString< 8 > & getContents()
void setLayoutOrder(unsigned Value)
static bool FixedEncode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, raw_ostream &OS, uint32_t *Offset, uint32_t *Size)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas using fixed length operands...
virtual bool evaluateTargetFixup(const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFixup &Fixup, const MCFragment *DF, const MCValue &Target, uint64_t &Value, bool &WasForced)
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
virtual bool shouldInsertFixupForCodeAlign(MCAssembler &Asm, const MCAsmLayout &Layout, MCAlignFragment &AF)
Hook which indicates if the target requires a fixup to be generated when handling an align directive ...
Should this fixup be evaluated in a target dependent manner?
virtual void executePostLayoutBinding(MCAssembler &Asm, const MCAsmLayout &Layout)=0
Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
A raw_ostream that writes to an SmallVector or SmallString.
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
FragmentType getKind() const
STATISTIC(NumFunctions, "Total number of functions")
const MCExpr & getOffset() const
bool isBundlingEnabled() const
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
static void Encode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, raw_ostream &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
symbol_iterator symbol_begin()
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
unsigned getBundleAlignSize() const
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
MCContext & getContext() const
int64_t getConstant() const
const MCSymbolRefExpr * getSymB() const
Interface implemented by fragments that contain encoded instructions and/or data. ...
fixup_iterator fixup_end()
virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout)=0
Write the object file and returns the number of bytes written.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
MCDwarfLineTableParams getDWARFLinetableParams() const
Encapsulates the layout of an assembly file at a particular point in time.
bool isSymbolLinkerVisible(const MCSymbol &SD) const
Check whether a particular symbol is visible to the linker and is required in the symbol table...
MCCodeEmitter & getEmitter() const
virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
Base class for the full range of assembler expressions which are needed for parsing.
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
bool registerSection(MCSection &Section)
The access may reference the value stored in memory.
Align getAlignment() const
static MCFixup createSubFor(const MCFixup &Fixup)
Return a fixup corresponding to the sub half of a add/sub fixup pair for the given Fixup...
Represent a reference to a symbol from inside an expression.
MCObjectWriter & getWriter() const
virtual bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout, const bool WasForced) const
Target specific predicate for whether a given fixup requires the associated instruction to be relaxed...
Context object for machine code objects.
const MCExpr & getAddrDelta() const
static bool mayCrossBoundary(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch crosses the boundary.
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
const MCExpr & getAddrDelta() const
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
void layoutFragment(MCFragment *Fragment)
Perform layout for a single fragment, assuming that the previous fragment has already been laid out c...
uint64_t value() const
This is a hole in the type system and should not be abused.
SmallVectorImpl< char > & getContents()
Instances of this class represent a single low-level machine instruction.
virtual unsigned getMinimumNopSize() const
Returns the minimum size of a nop in bytes on this target.
uint8_t getBundlePadding() const
Get the padding size that must be inserted before this fragment.
void encodeInlineLineTable(MCAsmLayout &Layout, MCCVInlineLineTableFragment &F)
Encodes the binary annotations once we have a layout.
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
virtual bool writeNopData(raw_ostream &OS, uint64_t Count) const =0
Write an (optimal) nop sequence of Count bytes to the given output.
bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
virtual void reset()
Lifetime management.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void invalidateFragmentsFrom(MCFragment *F)
Invalidate the fragments starting with F because it has been resized.
virtual void reset()
lifetime management
bool isRegistered() const
SmallVectorImpl< MCFixup > & getFixups()
bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const
Get the offset of the given symbol, as computed in the current layout.
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const
True if the section is atomized using the symbols in it.
const MCSymbol * getAtom(const MCSymbol &S) const
Find the symbol which defines the atom containing the given symbol, or null if there is no such symbo...
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
const MCSymbolRefExpr * getSymA() const
void reportError(SMLoc L, const Twine &Msg)
Should this fixup kind force a 4-byte aligned effective PC value?
const MCSymbol * getAtom() const
llvm::SmallVectorImpl< MCSection * > & getSectionOrder()
void setIsRegistered(bool Value)
uint32_t getOffset() const
void writeSectionData(raw_ostream &OS, const MCSection *Section, const MCAsmLayout &Layout) const
Emit the section contents to OS.
virtual bool UseCodeAlign() const =0
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
Binary assembler expressions.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
Fragment representing the .cv_def_range directive.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
raw_ostream & write(unsigned char C)
void layout(MCAsmLayout &Layout)
const MCExpr & getValue() const
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
PowerPC TLS Dynamic Call Fixup
void setOrdinal(unsigned Value)
Represents required padding such that a particular other set of fragments does not cross a particular...
Iterator for intrusive lists based on ilist_node.
unsigned getMaxBytesToEmit() const
MCAsmBackend * getBackendPtr() const
void writeFragmentPadding(raw_ostream &OS, const MCEncodedFragment &F, uint64_t FSize) const
Write the necessary bundle padding to OS.
MCAssembler(MCContext &Context, std::unique_ptr< MCAsmBackend > Backend, std::unique_ptr< MCCodeEmitter > Emitter, std::unique_ptr< MCObjectWriter > Writer)
Construct a new assembler instance.
virtual bool isVirtualSection() const =0
Check whether this section is "virtual", that is has no actual object file contents.
MCAsmBackend & getBackend() const
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
const MCSymbol & getSymbol() const
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
MCFragment * getFragment(bool SetUsed=true) const
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool isRegistered() const
Represents a symbol table index fragment.
An iterator type that allows iterating over the pointees via some other iterator. ...
virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)=0
Record a relocation entry.
static bool needPadding(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch needs padding.
MCLOHContainer & getLOHContainer()
void setBundlePadding(uint8_t N)
Set the padding size for this fragment.
uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCEncodedFragment *F, uint64_t FOffset, uint64_t FSize)
Compute the amount of padding required before the fragment F to obey bundling restrictions, where FOffset is the fragment's offset in its section and FSize is the fragment's size.
static bool isAgainstBoundary(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch is against the boundary.
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Target - Wrapper for Target specific information.
bool isThumbFunc(const MCSymbol *Func) const
Check whether a given symbol has been flagged with .thumb_func.
MCSection * getParent() const
uint64_t getValue() const
void setSize(uint64_t Value)
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
const MCSubtargetInfo * getSubtargetInfo() const
Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
void setIsRegistered(bool Value) const
Fragment representing the binary annotations produced by the .cv_inline_linetable directive...
bool isUsedInReloc() const
unsigned getValueSize() const
unsigned getAlignment() const
Represents a version number in the form major[.minor[.subminor[.build]]].
int64_t getLineDelta() const
const MCInst & getInst() const
static MCFixup createAddFor(const MCFixup &Fixup)
Return a fixup corresponding to the add half of a add/sub fixup pair for the given Fixup...
static void EncodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, raw_ostream &OS, uint32_t *Offset=nullptr, uint32_t *Size=nullptr)
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=nullptr, int64_t Val=0, uint32_t RefKind=0)
static MCFixupKind getKindForSizeInBits(unsigned Size, bool IsPCRel)
Return the generic fixup kind for a value with the given size in bits.
fixup_iterator fixup_begin()
Generic base class for all target subtargets.
bool evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const
Try to evaluate the expression to the form (a - b + constant) where neither a nor b are variables...
uint64_t computeFragmentSize(const MCAsmLayout &Layout, const MCFragment &F) const
Compute the effective fragment size assuming it is laid out at the given SectionAddress and FragmentO...
SmallString< 8 > & getContents()
const MCSymbol * getSymbol()
uint32_t getRefKind() const
CodeViewContext & getCVContext()
static MCFixupKind getKindForSize(unsigned Size, bool IsPCRel)
Return the generic fixup kind for a value with the given size.
void reset()
Reuse an assembler instance.
Fragment for data and encoded instructions.
uint64_t getSectionFileSize(const MCSection *Sec) const
Get the data size of the given section, as emitted to the object file.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
LLVM Value Representation.
uint64_t tell() const
tell - Return the current offset with the file.
This class implements an extremely fast bulk output stream that can only output to a stream...
const MCExpr * getValue() const
StringRef - Represent a constant reference to a string, i.e.
virtual void reset()
lifetime management
void Finish()
Finish - Do final processing and write the object to the output stream.
MCSection::FragmentListType & getFragmentList()
virtual void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, MutableArrayRef< char > Data, uint64_t Value, bool IsResolved, const MCSubtargetInfo *STI) const =0
Apply the Value for given Fixup into the provided data fragment, at the offset specified by the fixup...
virtual void finishLayout(MCAssembler const &Asm, MCAsmLayout &Layout) const
Give backend an opportunity to finish layout after relaxation.
void setInst(const MCInst &Value)
MCCodeEmitter * getEmitterPtr() const
MCFixupKind getKind() const
symbol_iterator symbol_end()