43 std::unique_ptr<MCAsmBackend> TAB,
44 std::unique_ptr<MCObjectWriter> OW,
45 std::unique_ptr<MCCodeEmitter> Emitter)
47 std::move(Emitter)) {}
49 bool MCELFStreamer::isBundleLocked()
const {
66 if (RequiredBundlePadding > UINT8_MAX)
69 if (RequiredBundlePadding > 0) {
81 for (
unsigned i = 0, e = EF->
getFixups().size(); i != e; ++i) {
101 auto *
Symbol = cast<MCSymbolELF>(S);
111 auto *
Symbol = cast<MCSymbolELF>(S);
147 const MCExpr *Subsection) {
149 if (CurSection && isBundleLocked())
156 const MCSymbol *Grp = SectionELF->getGroup();
191 auto *
Symbol = cast<MCSymbolELF>(S);
222 Symbol->setExternal(
true);
227 Symbol->setExternal(
true);
233 Symbol->setExternal(
true);
238 Symbol->setExternal(
false);
287 auto *
Symbol = cast<MCSymbolELF>(S);
290 if (!
Symbol->isBindingSet()) {
292 Symbol->setExternal(
true);
313 if(
Symbol->declareCommon(Size, ByteAlignment))
315 " redeclared as different type");
323 cast<MCSymbolELF>(
Symbol)->setSize(Value);
333 auto *
Symbol = cast<MCSymbolELF>(S);
337 Symbol->setExternal(
false);
343 if (isBundleLocked())
345 fixSymbolsInTLSFixups(Value);
352 unsigned MaxBytesToEmit) {
353 if (isBundleLocked())
356 ValueSize, MaxBytesToEmit);
379 void MCELFStreamer::fixSymbolsInTLSFixups(
const MCExpr *expr) {
382 cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(
getAssembler());
389 fixSymbolsInTLSFixups(be->
getLHS());
390 fixSymbolsInTLSFixups(be->
getRHS());
456 fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
461 void MCELFStreamer::finalizeCGProfileEntry(
const MCSymbolRefExpr *&SRE) {
466 SRE->
getLoc(),
Twine(
"Reference to undefined temporary symbol ") +
481 cast<MCSymbolELF>(S)->setExternal(
true);
485 void MCELFStreamer::finalizeCGProfile() {
487 finalizeCGProfileEntry(
E.From);
488 finalizeCGProfileEntry(
E.To);
492 void MCELFStreamer::EmitInstToFragment(
const MCInst &Inst,
497 for (
unsigned i = 0, e = F.
getFixups().size(); i != e; ++i)
498 fixSymbolsInTLSFixups(F.
getFixups()[i].getValue());
506 if (OldSTI && NewSTI && OldSTI != NewSTI)
510 void MCELFStreamer::EmitInstToData(
const MCInst &Inst,
518 for (
unsigned i = 0, e = Fixups.
size(); i != e; ++i)
519 fixSymbolsInTLSFixups(Fixups[i].getValue());
543 DF = BundleGroups.back();
546 else if (Assembler.
getRelaxAll() && !isBundleLocked())
557 else if (!isBundleLocked() && Fixups.
size() == 0) {
586 for (
unsigned i = 0, e = Fixups.
size(); i != e; ++i) {
594 if (!isBundleLocked()) {
602 assert(AlignPow2 <= 30 &&
"Invalid bundle alignment");
619 if (!isBundleLocked())
622 if (
getAssembler().getRelaxAll() && !isBundleLocked()) {
625 BundleGroups.push_back(DF);
638 else if (!isBundleLocked())
647 assert(!BundleGroups.empty() &&
"There are no bundle groups");
654 if (!isBundleLocked()) {
656 BundleGroups.pop_back();
697 std::unique_ptr<MCAsmBackend> &&MAB,
698 std::unique_ptr<MCObjectWriter> &&OW,
699 std::unique_ptr<MCCodeEmitter> &&CE,
702 new MCELFStreamer(Context, std::move(MAB), std::move(OW), std::move(CE));
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a local common (.lcomm) symbol.
void emitCGProfileEntry(const MCSymbolRefExpr *From, const MCSymbolRefExpr *To, uint64_t Count) override
const MCAsmInfo * getAsmInfo() const
Instances of this class represent a uniqued identifier for a section in the current translation unit...
void EmitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection)
void setUsedInReloc() const
bool hasInstructions() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
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.
.type _foo, STT_OBJECT # aka
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
VariantKind getKind() const
void EmitBundleUnlock() override
Ends a bundle-locked group.
void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override
Emit an ELF .size directive.
virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &)
Emit an instruction to a special fragment, because this instruction can change its size during relaxa...
void setAlignment(unsigned Value)
void setBundleLockState(BundleLockStateType NewState)
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
A raw_ostream that writes to an SmallVector or SmallString.
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
void PushSection()
Save the current and previous section on the section stack.
This is a compact (memory-size-wise) fragment for holding an encoded instruction (non-relaxable) that...
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.
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
.type _foo, STT_NOTYPE # aka
bool isBundlingEnabled() const
static unsigned CombineSymbolTypes(unsigned T1, unsigned T2)
void EmitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
unsigned getBundleAlignSize() const
unsigned getAlignment() const
MCContext & getContext() const
MCContext & getContext() const
void InitSections(bool NoExecStack) override
Create the default sections and set the initial one.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
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.
void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment=0) override
Emit a thread local bss (.tbss) symbol.
void setRelaxAll(bool Value)
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 EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
Represent a reference to a symbol from inside an expression.
void flushPendingLabels()
Create a dummy fragment to assign any pending labels.
void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override
Set the DescValue for the Symbol.
void EmitValueToAlignment(unsigned, int64_t, unsigned, unsigned) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void setSubsectionsViaSymbols(bool Value)
Context object for machine code objects.
void EmitThumbFunc(MCSymbol *Func) override
Note in the output that the specified Func is a Thumb mode function (ARM target only).
.code16 (X86) / .code 16 (ARM)
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Streaming object file generation interface.
.type _foo, STT_GNU_IFUNC
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.
void setBundleAlignSize(unsigned Size)
BundleLockStateType getBundleLockState() const
bool isBundleLocked() const
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
SmallVectorImpl< char > & getContents()
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...
Instances of this class represent a single low-level machine instruction.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
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...
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
void EmitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
Streaming machine code generation interface.
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
.weak_def_can_be_hidden (MachO)
The instances of the Type class are immutable: once they are created, they are never changed...
void insert(MCFragment *F)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void EmitCodeAlignment(unsigned ByteAlignment, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static void setSectionAlignmentForBundling(const MCAssembler &Assembler, MCSection *Section)
MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)
MCAssembler & getAssembler()
void setHasInstructions(const MCSubtargetInfo &STI)
Record that the fragment contains instructions with the MCSubtargetInfo in effect when the instructio...
void emitELFSymverDirective(StringRef AliasName, const MCSymbol *Aliasee) override
Emit an ELF .symver directive.
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
SmallVectorImpl< MCFixup > & getFixups()
bool isTemporary() const
isTemporary - Check if this is an assembler temporary symbol.
const MCObjectFileInfo * getObjectFileInfo() const
void reportError(SMLoc L, const Twine &Msg)
.subsections_via_symbols (MachO)
void EmitFrames(MCAsmBackend *MAB)
Binary assembler expressions.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
BlockVerifier::State From
void writeFragmentPadding(raw_ostream &OS, const MCEncodedFragment &F, uint64_t FSize) const
Write the necessary bundle padding to OS.
MCAsmBackend & getBackend() const
const MCSymbol & getSymbol() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static void CheckBundleSubtargets(const MCSubtargetInfo *OldSTI, const MCSubtargetInfo *NewSTI)
.type _foo, STT_TLS # aka
MCSymbol * getBeginSymbol()
void setVariableValue(const MCExpr *Value)
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.
MCSection * getCurrentSectionOnly() const
const MCSubtargetInfo * getSubtargetInfo() const
Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
.code32 (X86) / .code 32 (ARM)
.type _foo, STT_COMMON # aka
MCELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
std::vector< CGProfileEntry > CGProfile
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...
virtual void handleAssemblerFlag(MCAssemblerFlag Flag)
Handle any target-specific assembler flags. By default, do nothing.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
void FinishImpl() override
Streamer specific finalization.
.type _foo, STT_FUNC # aka
Generic base class for all target subtargets.
This represents a section on linux, lots of unix variants and some bare metal systems.
References to labels and assigned expressions.
bool isBundleGroupBeforeFirstInst() const
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.
void setBundleGroupBeforeFirstInst(bool IsFirst)
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
MCFragment * getCurrentFragment() const
void setAlignToBundleEnd(bool V)
StringRef getName() const
getName - Get the symbol name.
Fragment for data and encoded instructions.
void EmitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
MCSection * getTextSection() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool PopSection()
Restore the current and previous section from the section stack.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
LLVM Value Representation.
void EmitAssemblerFlag(MCAssemblerFlag Flag) override
Note in the output the specified Flag.
StringRef - Represent a constant reference to a string, i.e.
Target specific expression.
unsigned getFlags() const
Represents a location in source code.
void FinishImpl() override
Streamer specific finalization.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
std::vector< std::pair< StringRef, const MCSymbol * > > Symvers