Go to the documentation of this file.
43 std::unique_ptr<MCAsmBackend> TAB,
44 std::unique_ptr<MCObjectWriter> OW,
45 std::unique_ptr<MCCodeEmitter> Emitter)
49 bool MCELFStreamer::isBundleLocked()
const {
64 Assembler, EF,
DF->getContents().size(), FSize);
66 if (RequiredBundlePadding > UINT8_MAX)
69 if (RequiredBundlePadding > 0) {
75 DF->getContents().append(Code.begin(), Code.end());
83 DF->getContents().size());
101 auto *
Symbol = cast<MCSymbolELF>(
S);
112 auto *
Symbol = cast<MCSymbolELF>(
S);
148 const MCExpr *Subsection) {
150 if (CurSection && isBundleLocked())
156 auto *SectionELF =
static_cast<const MCSectionELF *
>(Section);
157 const MCSymbol *Grp = SectionELF->getGroup();
159 Asm.registerSymbol(*Grp);
161 Asm.getWriter().markGnuAbi();
164 Asm.registerSymbol(*Section->getBeginSymbol());
194 auto *
Symbol = cast<MCSymbolELF>(
S);
238 " changed binding to STB_GLOBAL");
256 " changed binding to STB_LOCAL");
309 auto *
Symbol = cast<MCSymbolELF>(
S);
312 if (!
Symbol->isBindingSet())
331 " redeclared as different type");
344 bool KeepOriginalSym) {
351 auto *
Symbol = cast<MCSymbolELF>(
S);
360 if (isBundleLocked())
362 fixSymbolsInTLSFixups(
Value);
369 unsigned MaxBytesToEmit) {
370 if (isBundleLocked())
373 ValueSize, MaxBytesToEmit);
396 void MCELFStreamer::fixSymbolsInTLSFixups(
const MCExpr *expr) {
399 cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(
getAssembler());
406 fixSymbolsInTLSFixups(
be->getLHS());
407 fixSymbolsInTLSFixups(
be->getRHS());
478 fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
483 void MCELFStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE,
486 if (
S->isTemporary()) {
487 if (!
S->isInSection()) {
489 SRE->
getLoc(),
Twine(
"Reference to undefined temporary symbol ") +
490 "`" +
S->getName() +
"`");
493 S =
S->getSection().getBeginSymbol();
500 if (
Optional<std::pair<bool, std::string>> Err =
502 *MCOffset,
"BFD_RELOC_NONE", SRE, SRE->
getLoc(),
508 void MCELFStreamer::finalizeCGProfile() {
510 if (
Asm.CGProfile.empty())
519 finalizeCGProfileEntry(
E.From, Offset);
520 finalizeCGProfileEntry(
E.To, Offset);
527 void MCELFStreamer::emitInstToFragment(
const MCInst &Inst,
532 for (
auto &Fixup :
F.getFixups())
533 fixSymbolsInTLSFixups(
Fixup.getValue());
541 if (OldSTI && NewSTI && OldSTI != NewSTI)
545 void MCELFStreamer::emitInstToData(
const MCInst &Inst,
553 for (
auto &Fixup :
Fixups)
554 fixSymbolsInTLSFixups(
Fixup.getValue());
578 DF = BundleGroups.back();
581 else if (Assembler.
getRelaxAll() && !isBundleLocked())
592 else if (!isBundleLocked() &&
Fixups.size() == 0) {
610 DF->setAlignToBundleEnd(
true);
621 for (
auto &Fixup :
Fixups) {
622 Fixup.setOffset(
Fixup.getOffset() +
DF->getContents().size());
623 DF->getFixups().push_back(Fixup);
626 DF->setHasInstructions(STI);
627 DF->getContents().append(
Code.begin(),
Code.end());
630 if (!isBundleLocked()) {
638 assert(AlignPow2 <= 30 &&
"Invalid bundle alignment");
653 if (!isBundleLocked())
659 BundleGroups.push_back(
DF);
671 else if (!isBundleLocked())
680 assert(!BundleGroups.empty() &&
"There are no bundle groups");
687 if (!isBundleLocked()) {
689 BundleGroups.pop_back();
701 if (!GNUAttributes.empty()) {
702 MCSection *DummyAttributeSection =
nullptr;
704 DummyAttributeSection, GNUAttributes);
737 bool OverwriteExisting) {
740 if (!OverwriteExisting)
743 Item->IntValue =
Value;
754 bool OverwriteExisting) {
757 if (!OverwriteExisting)
760 Item->StringValue = std::string(
Value);
772 bool OverwriteExisting) {
775 if (!OverwriteExisting)
778 Item->IntValue = IntValue;
779 Item->StringValue = std::string(StringValue);
785 IntValue, std::string(StringValue)};
790 MCELFStreamer::getAttributeItem(
unsigned Attribute) {
800 for (
size_t I = 0;
I < AttrsVec.size(); ++
I) {
801 AttributeItem Item = AttrsVec[
I];
811 Result += Item.StringValue.size() + 1;
816 Result += Item.StringValue.size() + 1;
823 void MCELFStreamer::createAttributesSection(
835 if (AttributeSection) {
846 const size_t VendorHeaderSize = 4 + Vendor.
size() + 1;
849 const size_t TagHeaderSize = 1 + 4;
851 const size_t ContentsSize = calculateContentSize(AttrsVec);
853 emitInt32(VendorHeaderSize + TagHeaderSize + ContentsSize);
862 for (
size_t I = 0;
I < AttrsVec.size(); ++
I) {
863 AttributeItem Item = AttrsVec[
I];
887 std::unique_ptr<MCAsmBackend> &&MAB,
888 std::unique_ptr<MCObjectWriter> &&OW,
889 std::unique_ptr<MCCodeEmitter> &&CE,
894 S->getAssembler().setRelaxAll(
true);
Optional< std::pair< bool, std::string > > emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc, const MCSubtargetInfo &STI) override
Record a relocation described by the .reloc directive.
MCAsmBackend & getBackend() const
bool isBundleLocked() const
VariantKind getKind() const
virtual void markGnuAbi()
ELF only. Mark that we have seen GNU ABI usage (e.g. SHF_GNU_RETAIN).
const MCObjectFileInfo * getObjectFileInfo() const
void visitUsedExpr(const MCExpr &Expr)
This is an optimization pass for GlobalISel generic memory operations.
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
virtual unsigned getTextSectionAlignment() const
void setHasInstructions(const MCSubtargetInfo &STI)
Record that the fragment contains instructions with the MCSubtargetInfo in effect when the instructio...
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
std::vector< Symver > Symvers
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
void setBundleLockState(BundleLockStateType NewState)
void emitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
Context object for machine code objects.
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
@ MCSA_Invalid
Not a valid directive.
void emitZerofill(MCSection *Section, MCSymbol *Symbol=nullptr, uint64_t Size=0, unsigned ByteAlignment=0, SMLoc L=SMLoc()) override
Emit the zerofill section and an optional symbol.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
void emitInt8(uint64_t Value)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
void changeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
virtual void handleAssemblerFlag(MCAssemblerFlag Flag)
Handle any target-specific assembler flags. By default, do nothing.
MCELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
virtual void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment *F, uint64_t Offset)
BundleLockStateType getBundleLockState() const
unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
The instances of the Type class are immutable: once they are created, they are never changed.
void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment=0) override
Emit a thread local bss (.tbss) symbol.
bool popSection()
Restore the current and previous section from the section stack.
void emitInt32(uint64_t Value)
@ NumericAndTextAttributes
@ MCSA_ELF_TypeNoType
.type _foo, STT_NOTYPE # aka @notype
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
Instances of this class represent a single low-level machine instruction.
SmallVectorImpl< MCFixup > & getFixups()
This represents a section on linux, lots of unix variants and some bare metal systems.
void setVariableValue(const MCExpr *Value)
void setBundleGroupBeforeFirstInst(bool IsFirst)
Binary assembler expressions.
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
Streaming machine code generation interface.
@ SHT_LLVM_CALL_GRAPH_PROFILE
Represents a location in source code.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
MCContext & getContext() const
@ Target
Target specific expression.
@ MCSA_Extern
.extern (XCOFF)
@ MCSA_AltEntry
.alt_entry (MachO)
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.
@ MCSA_Protected
.protected (ELF)
virtual void switchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
@ MCSA_LazyReference
.lazy_reference (MachO)
void emitCGProfileEntry(const MCSymbolRefExpr *From, const MCSymbolRefExpr *To, uint64_t Count) override
@ MCSA_LGlobal
.lglobl (XCOFF)
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
@ MCAF_Code16
.code16 (X86) / .code 16 (ARM)
Streaming object file generation interface.
@ MCSA_ELF_TypeIndFunction
.type _foo, STT_GNU_IFUNC
@ MCSA_Reference
.reference (MachO)
void emitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can be
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
const MCSymbol & getSymbol() const
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
@ MCSA_Hidden
.hidden (ELF)
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
@ MCSA_ELF_TypeGnuUniqueObject
SmallVector< AttributeItem, 64 > Contents
void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment *F, uint64_t Offset) override
MCFragment * getCurrentFragment() const
void setBundleAlignSize(unsigned Size)
MCSection * getCurrentSectionOnly() const
MCSection * getTextSection() const
@ Binary
Binary expressions.
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
@ MCSA_Exported
.globl _foo, exported (XCOFF)
void emitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void emitThumbFunc(MCSymbol *Func) override
Note in the output that the specified Func is a Thumb mode function (ARM target only).
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
void finishImpl() override
Streamer specific finalization.
void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name, bool KeepOriginalSym) override
Emit an ELF .symver directive.
MCCodeEmitter & getEmitter() const
@ MCAF_SubsectionsViaSymbols
.subsections_via_symbols (MachO)
void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a local common (.lcomm) symbol.
This is a compact (memory-size-wise) fragment for holding an encoded instruction (non-relaxable) that...
const MCAsmInfo * getAsmInfo() const
@ MCSA_WeakReference
.weak_reference (MachO)
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
void emitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override
Set the DescValue for the Symbol.
void setBundlePadding(uint8_t N)
Set the padding size for this fragment.
unsigned getBundleAlignSize() const
SMLoc getStartTokLoc() const
void insert(MCFragment *F)
void pushSection()
Save the current and previous section on the section stack.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
virtual void emitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
void reportError(SMLoc L, const Twine &Msg)
Represent a reference to a symbol from inside an expression.
MCAssembler & getAssembler()
void setAttributeItem(unsigned Attribute, unsigned Value, bool OverwriteExisting)
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.
MCDataFragment * getOrCreateDataFragment(const MCSubtargetInfo *STI=nullptr)
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment.
PowerPC TLS Dynamic Call Fixup
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection)
StringRef - Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setAttributeItems(unsigned Attribute, unsigned IntValue, StringRef StringValue, bool OverwriteExisting)
Instances of this class represent a uniqued identifier for a section in the current translation unit.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
@ MCSA_ELF_TypeTLS
.type _foo, STT_TLS # aka @tls_object
virtual void emitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &)
Emit an instruction to a special fragment, because this instruction can change its size during relaxa...
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
static unsigned CombineSymbolTypes(unsigned T1, unsigned T2)
@ MCSA_Internal
.internal (ELF)
ELF object attributes section emission support.
@ MCAF_Code32
.code32 (X86) / .code 32 (ARM)
@ MCSA_ELF_TypeCommon
.type _foo, STT_COMMON # aka @common
MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)
bool isBundleGroupBeforeFirstInst() const
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
@ MCAF_Code64
.code64 (X86)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void emitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
@ MCAF_SyntaxUnified
.syntax (ARM/ELF)
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
const MCSubtargetInfo * getSubtargetInfo() const
Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void emitAssemblerFlag(MCAssemblerFlag Flag) override
Note in the output the specified Flag.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_WeakDefinition
.weak_definition (MachO)
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
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,...
void setAlignToBundleEnd(bool V)
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
void flushPendingLabels()
Create a data fragment for any pending labels across all Sections and Subsections.
void emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
MCContext & getContext() const
@ SymbolRef
References to labels and assigned expressions.
@ Unary
Unary expressions.
void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override
Emit an ELF .size directive.
void emitBundleUnlock() override
Ends a bundle-locked group.
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
virtual MCSection * getNonexecutableStackSection(MCContext &Ctx) const
Targets can implement this method to specify a section to switch to if the translation unit doesn't h...
@ Constant
Constant expressions.
void initSections(bool NoExecStack, const MCSubtargetInfo &STI) override
Create the default sections and set the initial one.
void setSubsectionsViaSymbols(bool Value)
A raw_ostream that writes to an SmallVector or SmallString.
@ MCSA_PrivateExtern
.private_extern (MachO)
void writeFragmentPadding(raw_ostream &OS, const MCEncodedFragment &F, uint64_t FSize) const
Write the necessary bundle padding to OS.
BlockVerifier::State From
void finishImpl() override
Streamer specific finalization.
void emitFrames(MCAsmBackend *MAB)
void emitCodeAlignment(unsigned ByteAlignment, const MCSubtargetInfo *STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
Fragment for data and encoded instructions.
bool isBundlingEnabled() const
Generic base class for all target subtargets.
static void CheckBundleSubtargets(const MCSubtargetInfo *OldSTI, const MCSubtargetInfo *NewSTI)
LLVM Value Representation.
Base class for the full range of assembler expressions which are needed for parsing.
static void setSectionAlignmentForBundling(const MCAssembler &Assembler, MCSection *Section)
SmallVectorImpl< char > & getContents()
void reportWarning(SMLoc L, const Twine &Msg)
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.
void emitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
MCObjectWriter & getWriter() const
std::vector< CGProfileEntry > CGProfile