41 bool MCELFStreamer::isBundleLocked()
const {
61 if (RequiredBundlePadding > UINT8_MAX)
64 if (RequiredBundlePadding > 0) {
80 for (
unsigned i = 0, e = EF->
getFixups().size();
i != e; ++
i) {
99 auto *
Symbol = cast<MCSymbolELF>(S);
100 assert(
Symbol->isUndefined() &&
"Cannot define a symbol twice!");
137 const MCExpr *Subsection) {
139 if (CurSection && isBundleLocked())
146 const MCSymbol *Grp = SectionELF->getGroup();
152 auto *Begin = cast_or_null<MCSymbolELF>(Section->
getBeginSymbol());
157 if (Begin->isUndefined()) {
190 auto *
Symbol = cast<MCSymbolELF>(S);
232 Symbol->setExternal(
true);
237 Symbol->setExternal(
true);
243 Symbol->setExternal(
true);
248 Symbol->setExternal(
false);
297 auto *
Symbol = cast<MCSymbolELF>(S);
300 if (!
Symbol->isBindingSet()) {
302 Symbol->setExternal(
true);
323 if(
Symbol->declareCommon(Size, ByteAlignment))
325 " redeclared as different type");
333 cast<MCSymbolELF>(
Symbol)->setSize(Value);
338 auto *
Symbol = cast<MCSymbolELF>(S);
342 Symbol->setExternal(
false);
348 if (isBundleLocked())
350 fixSymbolsInTLSFixups(Value);
357 unsigned MaxBytesToEmit) {
358 if (isBundleLocked())
361 ValueSize, MaxBytesToEmit);
385 void MCELFStreamer::fixSymbolsInTLSFixups(
const MCExpr *expr) {
388 cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(
getAssembler());
395 fixSymbolsInTLSFixups(be->
getLHS());
396 fixSymbolsInTLSFixups(be->
getRHS());
458 fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
463 void MCELFStreamer::EmitInstToFragment(
const MCInst &Inst,
468 for (
unsigned i = 0, e = F.
getFixups().size();
i != e; ++
i)
469 fixSymbolsInTLSFixups(F.
getFixups()[
i].getValue());
472 void MCELFStreamer::EmitInstToData(
const MCInst &Inst,
480 for (
unsigned i = 0, e = Fixups.
size();
i != e; ++
i)
481 fixSymbolsInTLSFixups(Fixups[
i].getValue());
505 DF = BundleGroups.back();
506 else if (Assembler.
getRelaxAll() && !isBundleLocked())
515 else if (!isBundleLocked() && Fixups.
size() == 0) {
543 for (
unsigned i = 0, e = Fixups.
size();
i != e; ++
i) {
551 if (!isBundleLocked()) {
559 assert(AlignPow2 <= 30 &&
"Invalid bundle alignment");
576 if (!isBundleLocked())
579 if (
getAssembler().getRelaxAll() && !isBundleLocked()) {
582 BundleGroups.push_back(DF);
595 else if (!isBundleLocked())
604 assert(!BundleGroups.empty() &&
"There are no bundle groups");
611 if (!isBundleLocked()) {
613 BundleGroups.pop_back();
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a local common (.lcomm) symbol.
MCSymbolELF * getOrCreateSectionSymbol(const MCSectionELF &Section)
Instances of this class represent a uniqued identifier for a section in the current translation unit...
virtual MCObjectWriter * createObjectWriter(raw_pwrite_stream &OS) const =0
Create a new MCObjectWriter instance for use by the assembler backend to emit the final object file...
void EmitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
const MCAsmInfo * getAsmInfo() const
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
bool hasInstructions() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void EmitLabel(MCSymbol *Symbol) override
Emit a label for Symbol into the current section.
.type _foo, STT_OBJECT # aka
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
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 EmitZerofill(MCSection *Section, MCSymbol *Symbol=nullptr, uint64_t Size=0, unsigned ByteAlignment=0) override
Emit the zerofill section and an optional symbol.
unsigned getBundleAlignSize() const
void setAlignment(unsigned Value)
void writeFragmentPadding(const MCFragment &F, uint64_t FSize, MCObjectWriter *OW) const
Write the necessary bundle padding to the given object writer.
unsigned getFlags() const
void setBundleLockState(BundleLockStateType NewState)
MCCodeEmitter & getEmitter() const
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 EmitCOFFSymbolType(int Type) override
Emit the type of the symbol.
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
std::vector< IndirectSymbolData > & getIndirectSymbols()
.type _foo, STT_NOTYPE # aka
unsigned getAlignment() const
COFF::SymbolStorageClass StorageClass
void BeginCOFFSymbolDef(const MCSymbol *Symbol) override
Start emitting COFF symbol definition.
MCContext & getContext() const
static unsigned CombineSymbolTypes(unsigned T1, unsigned T2)
Defines the object file and target independent interfaces used by the assembler backend to write nati...
void EmitIdent(StringRef IdentString) override
Emit the "identifiers" directive.
void InitSections(bool NoExecStack) override
Create the default sections and set the initial one.
MCFragment * getCurrentFragment() const
void EmitFileDirective(StringRef Filename) override
Switch to a new logical file.
MCSectionSubPair getCurrentSection() const
Return the current section that the streamer is emitting code to.
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)
MCSection * getCurrentSectionOnly() const
Base class for the full range of assembler expressions which are needed for parsing.
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void EmitLabel(MCSymbol *Symbol) override
Emit a label for Symbol into the current section.
Represent a reference to a symbol from inside an expression.
void setAlignToBundleEnd(bool V)
MCContext & getContext() const
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).
void setHasInstructions(bool V)
.code16 (X86) / .code 16 (ARM)
.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.
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
void setBundleAlignSize(unsigned Size)
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...
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
void EmitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
Streaming machine code generation interface.
.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)
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)
MCAssembler & getAssembler()
MCCodeEmitter - Generic instruction encoding interface.
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
SmallVectorImpl< MCFixup > & getFixups()
.subsections_via_symbols (MachO)
MCSection * getTextSection() const
void EmitFrames(MCAsmBackend *MAB)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
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.
uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCFragment *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.
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool isBundlingEnabled() const
.type _foo, STT_TLS # aka
MCSymbol * getBeginSymbol()
MCStreamer * createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *CE, bool RelaxAll)
Takes ownership of TAB and CE.
void setVariableValue(const MCExpr *Value)
void addFileName(StringRef FileName)
void flushPendingLabels(MCFragment *F, uint64_t FOffset=0)
If any labels have been emitted but not assigned fragments, ensure that they get assigned, either to F if possible or to a new data fragment.
.code32 (X86) / .code 32 (ARM)
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
.type _foo, STT_COMMON # aka
void setBundlePadding(uint8_t N)
Set the padding size for this 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
MCAsmBackend & getBackend() const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool isBundleGroupBeforeFirstInst() const
MCSubtargetInfo - 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.
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.
BundleLockStateType getBundleLockState() const
void setBundleGroupBeforeFirstInst(bool IsFirst)
An abstract base class for streams implementations that also support a pwrite operation.
Fragment for data and encoded instructions.
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...
VariantKind getKind() const
void EmitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
cl::opt< bool > RelaxAll("mc-relax-all", cl::desc("When used with filetype=obj, ""relax all fixups in the emitted object file"))
bool PopSection()
Restore the current and previous section from the section stack.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
LLVM Value Representation.
Generic interface to target specific assembler backends.
const MCObjectFileInfo * getObjectFileInfo() const
bool isBundleLocked() const
void EndCOFFSymbolDef() override
Marks the end of the symbol definition.
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.
~MCELFStreamer() override
Represents a location in source code.
void FinishImpl() override
Streamer specific finalization.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
MCDataFragment * getOrCreateDataFragment()
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment...
void EmitCOFFSymbolStorageClass(int StorageClass) override
Emit the storage class of the symbol.
void setBeginSymbol(MCSymbol *Sym)