43 std::unique_ptr<MCAsmBackend> TAB,
44 std::unique_ptr<MCObjectWriter> OW,
45 std::unique_ptr<MCCodeEmitter>
Emitter)
58 if (Ctx.getTargetTriple().isLFI())
87 getStartTokLoc(),
"unterminated .bundle_lock when changing a section");
92 auto *SectionELF =
static_cast<const MCSectionELF *
>(Section);
93 const MCSymbol *Grp = SectionELF->getGroup();
95 Asm.registerSymbol(*Grp);
100 auto *Sym =
static_cast<MCSymbolELF *
>(Section->getBeginSymbol());
107 if (
A->isDefined()) {
109 "' is already defined");
184 " changed binding to STB_GLOBAL");
192 if (Symbol->isBindingSet() && Symbol->getBinding() !=
ELF::STB_WEAK)
194 getStartTokLoc(), Symbol->getName() +
" changed binding to STB_WEAK");
199 if (Symbol->isBindingSet() && Symbol->getBinding() !=
ELF::STB_LOCAL)
202 " changed binding to STB_LOCAL");
237 Symbol->setMemtag(
true);
259 Align ByteAlignment) {
263 if (!Symbol->isBindingSet())
280 if (Symbol->declareCommon(
Size, ByteAlignment))
282 " redeclared as different type");
294 bool KeepOriginalSym) {
300 Align ByteAlignment) {
332 if (!Asm.getBackend().allowBundling())
334 Loc,
"aligned bundling is not supported by this target");
335 if (Asm.isBundlingEnabled()) {
336 if (Asm.getBundleAlign() != Alignment)
338 ".bundle_align_mode cannot be changed once set");
343 if (Asm.getBackend().allowAutoPadding())
345 Loc,
".bundle_align_mode is incompatible with branch alignment");
348 Asm.setBundleAlign(Alignment);
356 if (!Asm.isBundlingEnabled())
358 Loc,
".bundle_lock forbidden when bundling is disabled");
364 Loc,
".bundle_lock is only allowed in an executable section");
369 BundleBA->setAlignToEnd(AlignToEnd);
376 if (!Asm.isBundlingEnabled())
378 Loc,
".bundle_unlock forbidden when bundling is disabled");
381 ".bundle_unlock without matching lock");
385 BundleBA->setLastFragment(CF);
387 uint64_t GroupSize = 0;
388 for (
const MCFragment *
F = BundleBA->getNext();;
F =
F->getNext()) {
392 "supported inside a .bundle_lock group");
395 GroupSize += Asm.computeFragmentSize(*
F);
396 if (
F == BundleBA->getLastFragment())
401 if (GroupSize > Asm.getBundleAlign().value())
403 Loc,
".bundle_lock group is larger than the bundle size");
417 SRE->
getLoc(),
Twine(
"Reference to undefined temporary symbol ") +
430void MCELFStreamer::finalizeCGProfile() {
432 if (
W.getCGProfile().empty())
442 for (
auto &
E :
W.getCGProfile()) {
443 finalizeCGProfileEntry(Sym,
Offset,
E.From);
444 finalizeCGProfileEntry(Sym,
Offset,
E.To);
457 auto *StackSec = Ctx.getAsmInfo().getStackSection(Ctx,
459 if (StackSec && Ctx.getTargetOptions().MCNoExecStack)
463 if (!GNUAttributes.empty()) {
464 MCSection *DummyAttributeSection =
nullptr;
466 DummyAttributeSection, GNUAttributes);
469 if (Ctx.getTargetTriple().isLFI())
479 bool OverwriteExisting) {
482 if (!OverwriteExisting)
485 Item->IntValue =
Value;
496 bool OverwriteExisting) {
499 if (!OverwriteExisting)
502 Item->StringValue = std::string(
Value);
514 bool OverwriteExisting) {
517 if (!OverwriteExisting)
520 Item->IntValue = IntValue;
521 Item->StringValue = std::string(StringValue);
527 IntValue, std::string(StringValue)};
532MCELFStreamer::getAttributeItem(
unsigned Attribute) {
533 for (AttributeItem &Item :
Contents)
539size_t MCELFStreamer::calculateContentSize(
542 for (
const AttributeItem &Item : AttrsVec) {
552 Result += Item.StringValue.size() + 1;
557 Result += Item.StringValue.size() + 1;
564void MCELFStreamer::createAttributesSection(
576 if (AttributeSection) {
587 const size_t VendorHeaderSize = 4 + Vendor.
size() + 1;
590 const size_t TagHeaderSize = 1 + 4;
592 const size_t ContentsSize = calculateContentSize(AttrsVec);
594 emitInt32(VendorHeaderSize + TagHeaderSize + ContentsSize);
626void MCELFStreamer::createAttributesWithSubsection(
635 if (0 == SubSectionVec.
size()) {
640 if (AttributeSection) {
652 const size_t VendorHeaderSize = 4 + SubSection.VendorName.size() + 1;
654 const size_t VendorParameters = 1 + 1;
655 const size_t ContentsSize = calculateContentSize(SubSection.Content);
657 emitInt32(VendorHeaderSize + VendorParameters + ContentsSize);
667 assert(0 &&
"Invalid attribute type");
684 SubSectionVec.clear();
688 std::unique_ptr<MCAsmBackend> &&MAB,
689 std::unique_ptr<MCObjectWriter> &&OW,
690 std::unique_ptr<MCCodeEmitter> &&CE) {
692 new MCELFStreamer(Context, std::move(MAB), std::move(OW), std::move(CE));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
dxil DXContainer Global Emitter
static unsigned CombineSymbolTypes(unsigned T1, unsigned T2)
LFI-specific code for MC.
This file defines the SmallVector class.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
SmallVector< const MCSymbolELF *, 0 > Weakrefs
SmallVector< Symver, 0 > Symvers
MCContext & getContext() const
MCObjectWriter & getWriter() const
LLVM_ABI bool registerSymbol(const MCSymbol &Symbol)
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
LLVM_ABI void reportWarning(SMLoc L, const Twine &Msg)
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
SmallVector< AttributeItem, 64 > Contents
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 initSections(const MCSubtargetInfo &STI) override
Create the default sections and set the initial one.
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.
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 emitBundleUnlock(const MCSubtargetInfo &STI) override
Ends a bundle-locked group.
void setAttributeItem(unsigned Attribute, unsigned Value, bool OverwriteExisting)
void finishImpl() final
Streamer specific finalization.
void emitBundleLock(bool AlignToEnd, const MCSubtargetInfo &STI) override
The following instructions are a bundle-locked group.
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void emitBundleAlignMode(Align Alignment) override
Enable aligned instruction bundling with the given bundle size, from this point onward.
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
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.
MCSection * getParent() const
FT * newSpecialFragment(Args &&...args)
void emitValueToAlignment(Align Alignment, int64_t Fill=0, uint8_t FillLen=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
MCAssembler & getAssembler()
void emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc={}) override
Record a relocation described by the .reloc directive.
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
void emitCodeAlignment(Align ByteAlignment, const MCSubtargetInfo &STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
virtual void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment &F, uint64_t Offset)
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
MCObjectStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
void finishImpl() override
Streamer specific finalization.
void changeSection(MCSection *Section, uint32_t Subsection=0) override
This is called by popSection and switchSection, if the current section changes.
bool isBundleLocked() const
SmallVector< CGProfileEntry, 0 > & getCGProfile()
This represents a section on linux, lots of unix variants and some bare metal systems.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
void ensureMinAlignment(Align MinAlignment)
Makes sure that Alignment is at least MinAlignment.
MCSymbol * getBeginSymbol()
Streaming machine code generation interface.
virtual bool popSection()
Restore the current and previous section from the section stack.
MCFragment * getCurrentFragment() const
MCContext & getContext() const
SMLoc getStartTokLoc() const
void setAllowAutoPadding(bool v)
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 pushSection()
Save the current and previous section on the section stack.
unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
void emitInt32(uint64_t Value)
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
MCSection * getCurrentSectionOnly() const
void emitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
void emitInt8(uint64_t Value)
Generic base class for all target subtargets.
LLVM_ABI void setBinding(unsigned Binding) const
Represent a reference to a symbol from inside an expression.
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
StringRef getName() const
getName - Get the symbol name.
void setUsedInReloc() const
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
Represents a location in source code.
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.
constexpr size_t size() const
Get the string size.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ SHT_LLVM_CALL_GRAPH_PROFILE
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
LLVM_ABI void emitLFINoteSection(MCStreamer &Streamer, MCContext &Ctx)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
std::pair< MCSection *, uint32_t > MCSectionSubPair
LLVM_ABI void emitLFIBundleAlign(MCStreamer &Streamer, MCContext &Ctx)
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
@ MCSA_Memtag
.memtag (ELF)
@ MCSA_Protected
.protected (ELF)
@ MCSA_OSLinkage
symbol uses OS linkage (GOFF)
@ MCSA_Exported
.globl _foo, exported (XCOFF)
@ MCSA_PrivateExtern
.private_extern (MachO)
@ MCSA_Internal
.internal (ELF)
@ MCSA_WeakReference
.weak_reference (MachO)
@ MCSA_AltEntry
.alt_entry (MachO)
@ MCSA_ELF_TypeIndFunction
.type _foo, STT_GNU_IFUNC
@ MCSA_LazyReference
.lazy_reference (MachO)
@ MCSA_ELF_TypeNoType
.type _foo, STT_NOTYPE # aka @notype
@ MCSA_Reference
.reference (MachO)
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
@ MCSA_ELF_TypeTLS
.type _foo, STT_TLS # aka @tls_object
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
@ MCSA_WeakDefinition
.weak_definition (MachO)
@ MCSA_ELF_TypeCommon
.type _foo, STT_COMMON # aka @common
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_WeakAntiDep
.weak_anti_dep (COFF)
@ MCSA_XPLinkage
symbol uses XP linkage (GOFF)
@ MCSA_Extern
.extern (XCOFF)
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
@ MCSA_ELF_TypeGnuUniqueObject
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
@ MCSA_Hidden
.hidden (ELF)
@ MCSA_LGlobal
.lglobl (XCOFF)
@ MCSA_Invalid
Not a valid directive.
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.
ELF object attributes section emission support.
@ NumericAndTextAttributes
ELF object attributes subsection support.